Skip to content

Commit

Permalink
add deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Sep 24, 2023
1 parent 32fe5eb commit e0ba363
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (e *EnvT) T() T {
// opt - fixture options, nil for default options.
// f - callback - fixture body.
// Cache guarantee for call f exactly once for same Cache called and params combination.
// Deprecated: will be removed in next versions.
// Use EnvT.CacheResult instead
func (e *EnvT) Cache(cacheKey interface{}, opt *FixtureOptions, f FixtureCallbackFunc) interface{} {
return e.cache(cacheKey, opt, f)
}
Expand All @@ -99,6 +101,8 @@ func (e *EnvT) Cache(cacheKey interface{}, opt *FixtureOptions, f FixtureCallbac
// f - callback - fixture body.
// cleanup, returned from f called while fixture cleanup
// Cache guarantee for call f exactly once for same Cache called and params combination.
// Deprecated: will be removed in next versions.
// Use EnvT.CacheResult instead
func (e *EnvT) CacheWithCleanup(cacheKey interface{}, opt *FixtureOptions, f FixtureCallbackWithCleanupFunc) interface{} {
if opt == nil {
opt = &FixtureOptions{}
Expand All @@ -119,6 +123,9 @@ func (e *EnvT) CacheWithCleanup(cacheKey interface{}, opt *FixtureOptions, f Fix
return e.cache(cacheKey, opt, fWithoutCleanup)
}

// CacheResult call f callback once and cache result (ok and error),
// then return same result for all calls of the callback without additional calls
// f with same options calls max once per test (or defined test scope)
func (e *EnvT) CacheResult(f FixtureFunction, options ...CacheOptions) interface{} {
var cacheOptions CacheOptions
switch len(options) {
Expand Down
6 changes: 4 additions & 2 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ type Env interface {
// Cache result of f calls
// f call exactly once for every combination of scope and params
// params must be json serializable (deserialize not need)
// Deprecated: Use CacheResult
// Deprecated: will be removed in next versions
// Use Env.CacheResult instead.
Cache(cacheKey interface{}, opt *FixtureOptions, f FixtureCallbackFunc) interface{}

// CacheWithCleanup cache result of f calls
// f call exactly once for every combination of scope and params
// params must be json serializable (deserialize not need)
// Deprecated: Use CacheResult
// Deprecated: will be removed in next versions
// Use Env.CacheResult instead.
CacheWithCleanup(cacheKey interface{}, opt *FixtureOptions, f FixtureCallbackWithCleanupFunc) interface{}
}

Expand Down

0 comments on commit e0ba363

Please sign in to comment.