@@ -10,42 +10,84 @@ import (
1010)
1111
1212func TestCacheGeneric (t * testing.T ) {
13- inParams := 123
14- inOpt := & FixtureOptions {Scope : ScopeTest }
15-
16- env := envMock {onCache : func (params interface {}, opt * FixtureOptions , f FixtureCallbackFunc ) interface {} {
17- require .Equal (t , inParams , params )
18- require .Equal (t , inOpt , opt )
19- res , _ := f ()
20- return res
21- }}
22-
23- res := Cache (env , inParams , inOpt , func () (int , error ) {
24- return 2 , nil
13+ t .Run ("PassParams" , func (t * testing.T ) {
14+ inParams := 123
15+ inOpt := & FixtureOptions {Scope : ScopeTest }
16+
17+ env := envMock {onCache : func (params interface {}, opt * FixtureOptions , f FixtureCallbackFunc ) interface {} {
18+ opt .additionlSkipExternalCalls --
19+ require .Equal (t , inParams , params )
20+ require .Equal (t , inOpt , opt )
21+ res , _ := f ()
22+ return res
23+ }}
24+
25+ res := Cache (env , inParams , inOpt , func () (int , error ) {
26+ return 2 , nil
27+ })
28+ require .Equal (t , 2 , res )
29+ })
30+ t .Run ("SkipAdditionalCache" , func (t * testing.T ) {
31+ test := & testMock {name : t .Name ()}
32+ env := newTestEnv (test )
33+
34+ f1 := func () int {
35+ return Cache (env , nil , nil , func () (int , error ) {
36+ return 1 , nil
37+ })
38+ }
39+ f2 := func () int {
40+ return Cache (env , nil , nil , func () (int , error ) {
41+ return 2 , nil
42+ })
43+ }
44+
45+ require .Equal (t , 1 , f1 ())
46+ require .Equal (t , 2 , f2 ())
2547 })
26- require .Equal (t , 2 , res )
2748}
2849
2950func TestCacheWithCleanupGeneric (t * testing.T ) {
30- inParams := 123
31- inOpt := & FixtureOptions {Scope : ScopeTest }
51+ t .Run ("PassParams" , func (t * testing.T ) {
52+ inParams := 123
53+ inOpt := & FixtureOptions {Scope : ScopeTest }
54+
55+ cleanupCalledBack := 0
3256
33- cleanupCalledBack := 0
57+ env := envMock {onCacheWithCleanup : func (params interface {}, opt * FixtureOptions , f FixtureCallbackWithCleanupFunc ) interface {} {
58+ opt .additionlSkipExternalCalls --
59+ require .Equal (t , inParams , params )
60+ require .Equal (t , inOpt , opt )
61+ res , _ , _ := f ()
62+ return res
63+ }}
3464
35- env := envMock {onCacheWithCleanup : func (params interface {}, opt * FixtureOptions , f FixtureCallbackWithCleanupFunc ) interface {} {
36- require .Equal (t , inParams , params )
37- require .Equal (t , inOpt , opt )
38- res , _ , _ := f ()
39- return res
40- }}
65+ res := CacheWithCleanup (env , inParams , inOpt , func () (int , FixtureCleanupFunc , error ) {
66+ cleanup := func () {
67+ cleanupCalledBack ++
68+ }
69+ return 2 , cleanup , nil
70+ })
71+ require .Equal (t , 2 , res )
72+ })
73+ t .Run ("SkipAdditionalCache" , func (t * testing.T ) {
74+ test := & testMock {name : t .Name ()}
75+ env := newTestEnv (test )
4176
42- res := CacheWithCleanup (env , inParams , inOpt , func () (int , FixtureCleanupFunc , error ) {
43- cleanup := func () {
44- cleanupCalledBack ++
77+ f1 := func () int {
78+ return CacheWithCleanup (env , nil , nil , func () (int , FixtureCleanupFunc , error ) {
79+ return 1 , nil , nil
80+ })
4581 }
46- return 2 , cleanup , nil
82+ f2 := func () int {
83+ return CacheWithCleanup (env , nil , nil , func () (int , FixtureCleanupFunc , error ) {
84+ return 2 , nil , nil
85+ })
86+ }
87+
88+ require .Equal (t , 1 , f1 ())
89+ require .Equal (t , 2 , f2 ())
4790 })
48- require .Equal (t , 2 , res )
4991
5092}
5193
0 commit comments