-
Notifications
You must be signed in to change notification settings - Fork 402
/
test.go
59 lines (50 loc) · 1.45 KB
/
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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package testsuite
import (
"strconv"
"testing"
"golang.org/x/sync/errgroup"
"storj.io/common/testcontext"
"storj.io/storj/private/kvstore"
)
// RunTests runs common kvstore.Store tests.
func RunTests(t *testing.T, store kvstore.Store) {
// store = storelogger.NewTest(t, store)
ctx := testcontext.New(t)
defer ctx.Cleanup()
t.Run("CRUD", func(t *testing.T) { testCRUD(t, ctx, store) })
t.Run("Constraints", func(t *testing.T) { testConstraints(t, ctx, store) })
t.Run("Range", func(t *testing.T) { testRange(t, ctx, store) })
t.Run("Parallel", func(t *testing.T) { testParallel(t, ctx, store) })
}
func testConstraints(t *testing.T, ctx *testcontext.Context, store kvstore.Store) {
var items kvstore.Items
for i := 0; i < 10; i++ {
items = append(items, kvstore.Item{
Key: kvstore.Key("test-" + strconv.Itoa(i)),
Value: kvstore.Value("xyz"),
})
}
var group errgroup.Group
for _, item := range items {
key := item.Key
value := item.Value
group.Go(func() error {
return store.Put(ctx, key, value)
})
}
if err := group.Wait(); err != nil {
t.Fatalf("Put failed: %v", err)
}
defer cleanupItems(t, ctx, store, items)
t.Run("Put Empty", func(t *testing.T) {
var key kvstore.Key
var val kvstore.Value
defer func() { _ = store.Delete(ctx, key) }()
err := store.Put(ctx, key, val)
if err == nil {
t.Fatal("putting empty key should fail")
}
})
}