Skip to content

Commit f9de235

Browse files
committed
Revert "add NoCache option"
This reverts commit 644db7b.
1 parent 9945dfd commit f9de235

File tree

4 files changed

+5
-50
lines changed

4 files changed

+5
-50
lines changed

cache.go

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package fixenv
22

33
import (
44
"errors"
5-
"strconv"
65
"sync"
76
)
87

@@ -14,10 +13,6 @@ type cache struct {
1413

1514
type cacheKey string
1615

17-
func (key *cacheKey) AppendNocacheCounter(counter int) {
18-
*key = cacheKey(string(*key) + "-nocache-" + strconv.Itoa(counter))
19-
}
20-
2116
type cacheVal struct {
2217
res interface{}
2318
err error

env.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ type EnvT struct {
2929
t T
3030
c *cache
3131

32-
m sync.Locker
33-
scopes map[string]*scopeInfo
34-
counter int
32+
m sync.Locker
33+
scopes map[string]*scopeInfo
3534
}
3635

3736
// NewEnv create EnvT from test
@@ -102,19 +101,12 @@ func (e *EnvT) cache(params interface{}, opt *FixtureOptions, f FixtureCallbackF
102101
if opt == nil {
103102
opt = globalEmptyFixtureOptions
104103
}
105-
106104
key, err := makeCacheKey(e.t.Name(), params, opt, false)
107105
if err != nil {
108106
e.t.Fatalf("failed to create cache key: %v", err)
109107
// return not reacheble after Fatalf
110108
return nil
111109
}
112-
113-
if opt.NoCache {
114-
e.counter++
115-
key.AppendNocacheCounter(e.counter)
116-
}
117-
118110
wrappedF := e.fixtureCallWrapper(key, f, opt)
119111
res, err := e.c.GetOrSet(key, wrappedF)
120112
if err != nil {

env_test.go

+1-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package fixenv
22

33
import (
44
"errors"
5-
"regexp"
65
"runtime"
76
"sync"
87
"testing"
@@ -148,29 +147,6 @@ func Test_Env_Cache(t *testing.T) {
148147
at.Equal(1, cntF())
149148
})
150149

151-
t.Run("NoCache", func(t *testing.T) {
152-
tMock := &testMock{name: t.Name()}
153-
env := newTestEnv(tMock)
154-
calledTimes := 0
155-
156-
fixture := func(e Env) int {
157-
return e.Cache(nil, &FixtureOptions{NoCache: true}, func() (res interface{}, err error) {
158-
calledTimes++
159-
return calledTimes, nil
160-
}).(int)
161-
}
162-
163-
require.Equal(t, 0, calledTimes)
164-
165-
require.Equal(t, 1, fixture(env))
166-
require.Equal(t, 1, calledTimes)
167-
168-
// double, no cache
169-
require.Equal(t, 2, fixture(env))
170-
require.Equal(t, 2, calledTimes)
171-
172-
})
173-
174150
t.Run("subtest_and_test_scope", func(t *testing.T) {
175151
at := assert.New(t)
176152
e := NewEnv(t)
@@ -679,14 +655,10 @@ func Test_ScopeName(t *testing.T) {
679655
},
680656
}
681657

682-
noCacheRe := regexp.MustCompile(`-nocache-.*`)
683-
684658
for _, c := range table {
685659
t.Run(c.name, func(t *testing.T) {
686660
at := assert.New(t)
687-
name := makeScopeName(c.testName, c.scope)
688-
noCacheRe.ReplaceAllString(name, "-nocache-XXX")
689-
at.Equal(c.result, name)
661+
at.Equal(c.result, makeScopeName(c.testName, c.scope))
690662
})
691663
}
692664
})

interface.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ const (
4040

4141
// ScopePackage mean fixture function with same parameters called once per package
4242
// for use the scope with TearDown function developer must initialize global handler and cleaner at TestMain.
43-
ScopePackage
43+
ScopePackage CacheScope = iota
4444

4545
// ScopeTestAndSubtests mean fixture cached for top level test and subtests
46-
ScopeTestAndSubtests
46+
ScopeTestAndSubtests CacheScope = iota
4747
)
4848

4949
// FixtureCallbackFunc - function, which result can cached
@@ -72,10 +72,6 @@ type FixtureOptions struct {
7272
// Scope for cache result
7373
Scope CacheScope
7474

75-
// NoCache mean result will not cached
76-
// in the case fiexenv used for lifetime manages, or simple to common code style
77-
NoCache bool
78-
7975
// cleanupFunc if not nil - called for cleanup fixture results
8076
// internal implementation details
8177
cleanupFunc FixtureCleanupFunc

0 commit comments

Comments
 (0)