-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
41 lines (33 loc) · 812 Bytes
/
Copy pathexample_test.go
File metadata and controls
41 lines (33 loc) · 812 Bytes
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
//go:build go1.18
// +build go1.18
package simple
import (
"github.com/rekby/fixenv"
"math/rand"
"testing"
)
var global = -1
func FSingleRandom(e fixenv.Env) int {
var f fixenv.GenericFixtureFunction[int] = func() (*fixenv.GenericResult[int], error) {
return fixenv.NewGenericResult(rand.Int()), nil
}
return fixenv.CacheResult(e, f, fixenv.CacheOptions{Scope: fixenv.ScopePackage})
}
func TestFirst(t *testing.T) {
e := fixenv.New(t)
if global == -1 {
global = FSingleRandom(e)
}
if singleRnd := FSingleRandom(e); singleRnd != global {
t.Fatalf("%v != %v", singleRnd, global)
}
}
func TestSecond(t *testing.T) {
e := fixenv.New(t)
if global == -1 {
global = FSingleRandom(e)
}
if singleRnd := FSingleRandom(e); singleRnd != global {
t.Fatalf("%v != %v", singleRnd, global)
}
}