storj/storage/testsuite/test_list.go
JT Olio f1641af802 storage: add monkit task to missing places (#2122)
* storage: add monkit task to missing places

Change-Id: I9e17a6b14f7c25bbf698eeecf32785e9add3f26e

* fix tests

Change-Id: Id078276fa3de61a28eb3d01d4e751732ecbb173f

* import order

Change-Id: I814e33755b9f10b5219af37cd828cd75eb3da1a4

* remove part of other commit

Change-Id: Idaa4c95cd65e97567fb466de49718db8203cfbe1
2019-06-05 16:23:10 +02:00

75 lines
1.7 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package testsuite
import (
"math/rand"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"storj.io/storj/storage"
)
func testList(t *testing.T, store storage.KeyValueStore) {
items := storage.Items{
newItem("path/0", "\x00\xFF\x00", false),
newItem("path/1", "\x01\xFF\x01", false),
newItem("path/2", "\x02\xFF\x02", false),
newItem("path/3", "\x03\xFF\x03", false),
newItem("path/4", "\x04\xFF\x04", false),
newItem("path/5", "\x05\xFF\x05", false),
}
rand.Shuffle(len(items), items.Swap)
defer cleanupItems(store, items)
if err := storage.PutAll(ctx, store, items...); err != nil {
t.Fatalf("failed to setup: %v", err)
}
type Test struct {
Name string
First storage.Key
Limit int
Expected storage.Keys
}
newKeys := func(xs ...string) storage.Keys {
var keys storage.Keys
for _, x := range xs {
keys = append(keys, storage.Key(x))
}
return keys
}
tests := []Test{
{"without key",
nil, 3,
newKeys("path/0", "path/1", "path/2")},
{"without key, limit 0",
nil, 0,
newKeys("path/0", "path/1", "path/2", "path/3", "path/4", "path/5")},
{"with key",
storage.Key("path/2"), 3,
newKeys("path/2", "path/3", "path/4")},
{"without key 100",
nil, 100,
newKeys("path/0", "path/1", "path/2", "path/3", "path/4", "path/5")},
}
for _, test := range tests {
var keys storage.Keys
var err error
keys, err = store.List(ctx, test.First, test.Limit)
if err != nil {
t.Errorf("%s: %s", test.Name, err)
continue
}
if diff := cmp.Diff(test.Expected, keys, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("%s: (-want +got)\n%s", test.Name, diff)
}
}
}