-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterface.go
56 lines (44 loc) · 1.7 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package fixenv
// Env - fixture cache engine.
type Env interface {
// T - return t object of current test/benchmark.
T() T
// Cache cache result of f calls
// f call exactly once for every combination of scope and params
// params must be json serializable (deserialize not need)
Cache(params interface{}, opt *FixtureOptions, f FixtureCallbackFunc) interface{}
// Cleanup add callback cleanup function
// f called while env clean
Cleanup(f func())
}
type CacheScope int
const (
// ScopeTest mean fixture function with same parameters called once per every test and subtests. Default value.
// Second and more calls will use cached value.
ScopeTest CacheScope = iota
// 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 CacheScope = iota
// ScopeTestAndSubtests mean fixture cached for top level test and subtests
ScopeTestAndSubtests CacheScope = iota
)
// FixtureCallbackFunc - function, which result can cached
// res - result for cache.
// if err not nil - T().Fatalf() will called with error message
// if res exit without return (panic, GoExit, t.FailNow, ...)
// then cache error about unexpected exit
type FixtureCallbackFunc func() (res interface{}, err error)
type FixtureCleanupFunc func()
type FixtureOptions struct {
// Scope for cache result
Scope CacheScope
// CleanupFunc if not nil - called for cleanup fixture results
// it called exactly once for every succesully call fixture
CleanupFunc FixtureCleanupFunc
}
// T is subtype of testing.TB
type T interface {
Cleanup(func())
Fatalf(format string, args ...interface{})
Name() string
}