@@ -26,7 +26,7 @@ import (
2626 "github.com/stretchr/testify/assert"
2727 "github.com/stretchr/testify/require"
2828
29- "github.com/elastic/elastic-agent-libs/logp"
29+ "github.com/elastic/elastic-agent-libs/logp/logptest "
3030)
3131
3232var (
@@ -40,10 +40,10 @@ type cacheSetup struct {
4040 result Result
4141}
4242
43- func newCacheSetup (service string , exp time.Duration , init bool ) cacheSetup {
43+ func newCacheSetup (t testing. TB , service string , exp time.Duration , init bool ) cacheSetup {
4444 setup := cacheSetup {
4545 query : Query {Service : Service {Name : service }, Etag : "123" },
46- cache : newCache (logp . NewLogger ( "" ), exp ),
46+ cache : newCache (logptest . NewTestingLogger ( t , "" ), exp ),
4747 result : defaultResult ,
4848 }
4949 if init {
@@ -67,7 +67,7 @@ func TestCache_fetchAndAdd(t *testing.T) {
6767 "NilDocFromFunction" : {fetchFunc : testFnNil },
6868 } {
6969 t .Run (name , func (t * testing.T ) {
70- setup := newCacheSetup (name , exp , testCase .init )
70+ setup := newCacheSetup (t , name , exp , testCase .init )
7171
7272 doc , err := setup .cache .fetch (setup .query , testCase .fetchFunc )
7373 assert .Equal (t , testCase .doc , doc )
@@ -85,7 +85,7 @@ func TestCache_fetchAndAdd(t *testing.T) {
8585
8686 t .Run ("CacheKeyExpires" , func (t * testing.T ) {
8787 exp := 100 * time .Millisecond
88- setup := newCacheSetup (t .Name (), exp , false )
88+ setup := newCacheSetup (t , t .Name (), exp , false )
8989 doc , err := setup .cache .fetch (setup .query , testFn )
9090 require .NoError (t , err )
9191 require .NotNil (t , doc )
@@ -107,7 +107,7 @@ func BenchmarkFetchAndAdd(b *testing.B) {
107107 // intialize the cache and add a document to it before the benchmark,
108108 // to ensure docs are only fetched from cache
109109 exp := 5 * time .Minute
110- setup := newCacheSetup (b .Name (), exp , true )
110+ setup := newCacheSetup (b , b .Name (), exp , true )
111111 for i := 0 ; i < b .N ; i ++ {
112112 setup .cache .fetch (setup .query , testFn )
113113 }
@@ -117,7 +117,7 @@ func BenchmarkFetchAndAdd(b *testing.B) {
117117 // intialize the cache, test adding random docs to cache
118118 // to ensure a fetch and add operation per call
119119 exp := 5 * time .Minute
120- setup := newCacheSetup (b .Name (), exp , false )
120+ setup := newCacheSetup (b , b .Name (), exp , false )
121121 q := Query {Service : Service {}}
122122 for i := 0 ; i < b .N ; i ++ {
123123 q .Service .Name = fmt .Sprintf ("%v" , b .N )
0 commit comments