2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-05 17:10:35 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package testsuite
|
|
|
|
|
|
|
|
import (
|
2018-09-07 10:00:00 +01:00
|
|
|
"strconv"
|
2018-09-05 17:10:35 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RunTests runs common storage.KeyValueStore tests
|
|
|
|
func RunTests(t *testing.T, store storage.KeyValueStore) {
|
|
|
|
// store = storelogger.NewTest(t, store)
|
|
|
|
|
|
|
|
t.Run("CRUD", func(t *testing.T) { testCRUD(t, store) })
|
|
|
|
t.Run("Constraints", func(t *testing.T) { testConstraints(t, store) })
|
|
|
|
t.Run("Iterate", func(t *testing.T) { testIterate(t, store) })
|
|
|
|
t.Run("IterateAll", func(t *testing.T) { testIterateAll(t, store) })
|
|
|
|
t.Run("Prefix", func(t *testing.T) { testPrefix(t, store) })
|
|
|
|
|
|
|
|
t.Run("List", func(t *testing.T) { testList(t, store) })
|
|
|
|
t.Run("ListV2", func(t *testing.T) { testListV2(t, store) })
|
2018-11-20 15:26:20 +00:00
|
|
|
|
|
|
|
t.Run("Parallel", func(t *testing.T) { testParallel(t, store) })
|
2018-09-05 17:10:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func testConstraints(t *testing.T, store storage.KeyValueStore) {
|
2018-09-07 10:00:00 +01:00
|
|
|
var items storage.Items
|
|
|
|
for i := 0; i < storage.LookupLimit+5; i++ {
|
|
|
|
items = append(items, storage.ListItem{
|
|
|
|
Key: storage.Key("test-" + strconv.Itoa(i)),
|
|
|
|
Value: storage.Value("xyz"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range items {
|
|
|
|
if err := store.Put(item.Key, item.Value); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer cleanupItems(store, items)
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Run("Put Empty", func(t *testing.T) {
|
|
|
|
var key storage.Key
|
|
|
|
var val storage.Value
|
|
|
|
defer func() { _ = store.Delete(key) }()
|
|
|
|
|
|
|
|
err := store.Put(key, val)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("putting empty key should fail")
|
|
|
|
}
|
|
|
|
})
|
2018-09-07 10:00:00 +01:00
|
|
|
|
|
|
|
t.Run("GetAll limit", func(t *testing.T) {
|
|
|
|
_, err := store.GetAll(items[:storage.LookupLimit].GetKeys())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("GetAll LookupLimit should succeed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = store.GetAll(items[:storage.LookupLimit+1].GetKeys())
|
|
|
|
if err == nil && err == storage.ErrLimitExceeded {
|
|
|
|
t.Fatalf("GetAll LookupLimit+1 should fail: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("List limit", func(t *testing.T) {
|
|
|
|
keys, err := store.List(nil, storage.LookupLimit)
|
|
|
|
if err != nil || len(keys) != storage.LookupLimit {
|
|
|
|
t.Fatalf("List LookupLimit should succeed: %v / got %d", err, len(keys))
|
|
|
|
}
|
|
|
|
_, err = store.List(nil, storage.LookupLimit+1)
|
|
|
|
if err != nil || len(keys) != storage.LookupLimit {
|
|
|
|
t.Fatalf("List LookupLimit+1 shouldn't fail: %v / got %d", err, len(keys))
|
|
|
|
}
|
|
|
|
})
|
2018-09-05 17:10:35 +01:00
|
|
|
}
|