diff --git a/cache.go b/cache.go index cafd634..28f48eb 100644 --- a/cache.go +++ b/cache.go @@ -2,7 +2,6 @@ package fixenv import ( "errors" - "strconv" "sync" ) @@ -14,10 +13,6 @@ type cache struct { type cacheKey string -func (key *cacheKey) AppendNocacheCounter(counter int) { - *key = cacheKey(string(*key) + "-nocache-" + strconv.Itoa(counter)) -} - type cacheVal struct { res interface{} err error diff --git a/env.go b/env.go index 6e3cb64..bb4442c 100644 --- a/env.go +++ b/env.go @@ -29,9 +29,8 @@ type EnvT struct { t T c *cache - m sync.Locker - scopes map[string]*scopeInfo - counter int + m sync.Locker + scopes map[string]*scopeInfo } // NewEnv create EnvT from test @@ -102,19 +101,12 @@ func (e *EnvT) cache(params interface{}, opt *FixtureOptions, f FixtureCallbackF if opt == nil { opt = globalEmptyFixtureOptions } - key, err := makeCacheKey(e.t.Name(), params, opt, false) if err != nil { e.t.Fatalf("failed to create cache key: %v", err) // return not reacheble after Fatalf return nil } - - if opt.NoCache { - e.counter++ - key.AppendNocacheCounter(e.counter) - } - wrappedF := e.fixtureCallWrapper(key, f, opt) res, err := e.c.GetOrSet(key, wrappedF) if err != nil { diff --git a/env_test.go b/env_test.go index 9718086..3d9e6f2 100644 --- a/env_test.go +++ b/env_test.go @@ -2,7 +2,6 @@ package fixenv import ( "errors" - "regexp" "runtime" "sync" "testing" @@ -148,29 +147,6 @@ func Test_Env_Cache(t *testing.T) { at.Equal(1, cntF()) }) - t.Run("NoCache", func(t *testing.T) { - tMock := &testMock{name: t.Name()} - env := newTestEnv(tMock) - calledTimes := 0 - - fixture := func(e Env) int { - return e.Cache(nil, &FixtureOptions{NoCache: true}, func() (res interface{}, err error) { - calledTimes++ - return calledTimes, nil - }).(int) - } - - require.Equal(t, 0, calledTimes) - - require.Equal(t, 1, fixture(env)) - require.Equal(t, 1, calledTimes) - - // double, no cache - require.Equal(t, 2, fixture(env)) - require.Equal(t, 2, calledTimes) - - }) - t.Run("subtest_and_test_scope", func(t *testing.T) { at := assert.New(t) e := NewEnv(t) @@ -679,14 +655,10 @@ func Test_ScopeName(t *testing.T) { }, } - noCacheRe := regexp.MustCompile(`-nocache-.*`) - for _, c := range table { t.Run(c.name, func(t *testing.T) { at := assert.New(t) - name := makeScopeName(c.testName, c.scope) - noCacheRe.ReplaceAllString(name, "-nocache-XXX") - at.Equal(c.result, name) + at.Equal(c.result, makeScopeName(c.testName, c.scope)) }) } }) diff --git a/interface.go b/interface.go index 77655a5..c9c4e25 100644 --- a/interface.go +++ b/interface.go @@ -40,10 +40,10 @@ const ( // ScopePackage mean fixture function with same parameters called once per package // for use the scope with TearDown function developer must initialize global handler and cleaner at TestMain. - ScopePackage + ScopePackage CacheScope = iota // ScopeTestAndSubtests mean fixture cached for top level test and subtests - ScopeTestAndSubtests + ScopeTestAndSubtests CacheScope = iota ) // FixtureCallbackFunc - function, which result can cached @@ -72,10 +72,6 @@ type FixtureOptions struct { // Scope for cache result Scope CacheScope - // NoCache mean result will not cached - // in the case fiexenv used for lifetime manages, or simple to common code style - NoCache bool - // cleanupFunc if not nil - called for cleanup fixture results // internal implementation details cleanupFunc FixtureCleanupFunc