@@ -47,37 +47,36 @@ func newCacheSetup(service string, exp time.Duration, init bool) cacheSetup {
4747 result : defaultResult ,
4848 }
4949 if init {
50- setup .c .gocache .SetDefault (setup .result . Source . Etag , setup .result )
50+ setup .c .gocache .SetDefault (setup .q . toString () , setup .result )
5151 }
5252 return setup
5353}
5454
5555func TestCache_fetchAndAdd (t * testing.T ) {
5656 exp := time .Second
57- for name , tc := range map [string ]struct {
58- fn func () (Result , error )
59- init bool
60-
61- doc Result
62- fail bool
57+ for name , testCase := range map [string ]struct {
58+ fetchFunc func () (Result , error )
59+ init bool
60+ doc Result
61+ shouldFail bool
6362 }{
64- "DocFromCache" : {fn : testFn , init : true , doc : defaultResult },
65- "DocFromFunctionFails" : {fn : testFnErr , fail : true },
66- "DocFromFunction" : {fn : testFn , doc : externalResult },
67- "EmptyDocFromFunction" : {fn : testFnSettingsNil , doc : Result {Source {Settings : Settings {}}}},
68- "NilDocFromFunction" : {fn : testFnNil },
63+ "DocFromCache" : {fetchFunc : testFn , init : true , doc : defaultResult },
64+ "DocFromFunctionFails" : {fetchFunc : testFnErr , shouldFail : true },
65+ "DocFromFunction" : {fetchFunc : testFn , doc : externalResult },
66+ "EmptyDocFromFunction" : {fetchFunc : testFnSettingsNil , doc : Result {Source {Settings : Settings {}}}},
67+ "NilDocFromFunction" : {fetchFunc : testFnNil },
6968 } {
7069 t .Run (name , func (t * testing.T ) {
71- setup := newCacheSetup (name , exp , tc .init )
70+ setup := newCacheSetup (name , exp , testCase .init )
7271
73- doc , err := setup .c .fetch (setup .q , tc . fn )
74- assert .Equal (t , tc .doc , doc )
75- if tc . fail {
72+ doc , err := setup .c .fetch (setup .q , testCase . fetchFunc )
73+ assert .Equal (t , testCase .doc , doc )
74+ if testCase . shouldFail {
7675 require .Error (t , err )
7776 } else {
7877 assert .NoError (t , err )
7978 //ensure value is cached afterwards
80- cachedDoc , error := setup .c .fetch (setup .q , tc . fn )
79+ cachedDoc , error := setup .c .fetch (setup .q , testCase . fetchFunc )
8180 require .NoError (t , error )
8281 assert .Equal (t , doc , cachedDoc )
8382 }
0 commit comments