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 (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2018-09-07 10:00:00 +01:00
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
2018-10-16 12:43:44 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2018-10-16 12:43:44 +01:00
|
|
|
"storj.io/storj/storage"
|
2018-09-05 17:10:35 +01:00
|
|
|
)
|
|
|
|
|
2019-09-24 19:06:22 +01:00
|
|
|
func testList(t *testing.T, ctx *testcontext.Context, store storage.KeyValueStore) {
|
2018-09-05 17:10:35 +01:00
|
|
|
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)
|
2019-09-24 19:06:22 +01:00
|
|
|
defer cleanupItems(t, ctx, store, items)
|
2018-09-05 17:10:35 +01:00
|
|
|
|
2019-06-05 15:23:10 +01:00
|
|
|
if err := storage.PutAll(ctx, store, items...); err != nil {
|
2018-09-07 15:20:15 +01:00
|
|
|
t.Fatalf("failed to setup: %v", err)
|
2018-09-05 17:10:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Test struct {
|
|
|
|
Name string
|
|
|
|
First storage.Key
|
2018-09-07 15:20:15 +01:00
|
|
|
Limit int
|
2018-09-05 17:10:35 +01:00
|
|
|
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{
|
2019-02-13 17:27:03 +00:00
|
|
|
{"without key",
|
2018-09-05 17:10:35 +01:00
|
|
|
nil, 3,
|
|
|
|
newKeys("path/0", "path/1", "path/2")},
|
2019-02-13 17:27:03 +00:00
|
|
|
{"without key, limit 0",
|
2018-09-05 17:10:35 +01:00
|
|
|
nil, 0,
|
|
|
|
newKeys("path/0", "path/1", "path/2", "path/3", "path/4", "path/5")},
|
2019-02-13 17:27:03 +00:00
|
|
|
{"with key",
|
2018-09-05 17:10:35 +01:00
|
|
|
storage.Key("path/2"), 3,
|
|
|
|
newKeys("path/2", "path/3", "path/4")},
|
2019-02-13 17:27:03 +00:00
|
|
|
{"without key 100",
|
2018-09-05 17:10:35 +01:00
|
|
|
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
|
2019-06-05 15:23:10 +01:00
|
|
|
keys, err = store.List(ctx, test.First, test.Limit)
|
2018-09-05 17:10:35 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: %s", test.Name, err)
|
|
|
|
continue
|
|
|
|
}
|
2018-09-07 10:00:00 +01:00
|
|
|
if diff := cmp.Diff(test.Expected, keys, cmpopts.EquateEmpty()); diff != "" {
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Errorf("%s: (-want +got)\n%s", test.Name, diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|