forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkv_test.go
92 lines (77 loc) · 2.08 KB
/
kv_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package bolt_test
import (
"context"
"testing"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/kv"
platformtesting "github.com/influxdata/influxdb/testing"
)
func initKVStore(f platformtesting.KVStoreFields, t *testing.T) (kv.Store, func()) {
s, closeFn, err := NewTestKVStore()
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
err = s.Update(func(tx kv.Tx) error {
b, err := tx.Bucket(f.Bucket)
if err != nil {
return err
}
for _, p := range f.Pairs {
if err := b.Put(p.Key, p.Value); err != nil {
return err
}
}
return nil
})
if err != nil {
t.Fatalf("failed to put keys: %v", err)
}
return s, func() {
closeFn()
}
}
func TestKVStore(t *testing.T) {
platformtesting.KVStore(initKVStore, t)
}
func initExampleService(f platformtesting.UserFields, t *testing.T) (platform.UserService, string, func()) {
s, closeFn, err := NewTestKVStore()
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
svc := kv.NewExampleService(s, f.IDGenerator)
if err := svc.Initialize(); err != nil {
t.Fatalf("error initializing user service: %v", err)
}
ctx := context.Background()
for _, u := range f.Users {
if err := svc.PutUser(ctx, u); err != nil {
t.Fatalf("failed to populate users")
}
}
return svc, "kv/", func() {
defer closeFn()
for _, u := range f.Users {
if err := svc.DeleteUser(ctx, u.ID); err != nil {
t.Logf("failed to remove users: %v", err)
}
}
}
}
func TestExampleService_CreateUser(t *testing.T) {
platformtesting.CreateUser(initExampleService, t)
}
func TestExampleService_FindUserByID(t *testing.T) {
platformtesting.FindUserByID(initExampleService, t)
}
func TestExampleService_FindUsers(t *testing.T) {
platformtesting.FindUsers(initExampleService, t)
}
func TestExampleService_DeleteUser(t *testing.T) {
platformtesting.DeleteUser(initExampleService, t)
}
func TestExampleService_FindUser(t *testing.T) {
platformtesting.FindUser(initExampleService, t)
}
func TestExampleService_UpdateUser(t *testing.T) {
platformtesting.UpdateUser(initExampleService, t)
}