-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathkv_test.go
55 lines (44 loc) · 1.12 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
package bolt_test
import (
"context"
"fmt"
"testing"
"github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/kv/migration"
platformtesting "github.com/influxdata/influxdb/v2/testing"
)
func initKVStore(f platformtesting.KVStoreFields, t *testing.T) (kv.Store, func()) {
s, closeFn, err := NewTestKVStore(t)
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
mustCreateBucket(t, s, f.Bucket)
err = s.Update(context.Background(), 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 mustCreateBucket(t testing.TB, store kv.SchemaStore, bucket []byte) {
t.Helper()
migrationName := fmt.Sprintf("create bucket %q", string(bucket))
if err := migration.CreateBuckets(migrationName, bucket).Up(context.Background(), store); err != nil {
t.Fatal(err)
}
}