-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfake_test.go
More file actions
48 lines (40 loc) · 1000 Bytes
/
fake_test.go
File metadata and controls
48 lines (40 loc) · 1000 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
42
43
44
45
46
47
48
package testingdouble_test
import (
"context"
"testing"
"go.llib.dev/testcase"
"go.llib.dev/testcase/random"
)
type FakeXYStorage map[string]XY
func (f FakeXYStorage) CreateXY(ctx context.Context, ptr *XY) error {
rnd := random.New(random.CryptoSeed{})
if ptr.ID == `` {
ptr.ID = rnd.StringN(42) // not safe
}
f[ptr.ID] = *ptr
return nil
}
func (f FakeXYStorage) FindXYByID(ctx context.Context, ptr *XY, id string) (found bool, err error) {
ent, ok := f[id]
if !ok {
return false, nil
}
*ptr = ent
return true, nil
}
// file: FakeXYEntityStorage_test.go
var _ XYStorage = FakeXYStorage{}
func TestFakeXYEntityStorage_suppliesXYStorageContract(t *testing.T) {
XYStorageContract{
Subject: func(tb testing.TB) XYStorage {
return make(FakeXYStorage)
},
MakeCtx: func(tb testing.TB) context.Context {
return context.Background()
},
MakeXY: func(tb testing.TB) *XY {
t := testcase.NewTWithSpec(tb, nil)
return t.Random.Make(new(XY)).(*XY)
},
}.Test(t)
}