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"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2018-09-05 17:10:35 +01:00
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
2019-09-24 19:06:22 +01:00
|
|
|
func testPrefix(t *testing.T, ctx *testcontext.Context, store storage.KeyValueStore) {
|
2018-09-05 17:10:35 +01:00
|
|
|
items := storage.Items{
|
|
|
|
newItem("x-a", "a", false),
|
|
|
|
newItem("x-b/1", "b/1", false),
|
|
|
|
newItem("x-b/2", "b/2", false),
|
|
|
|
newItem("x-b/3", "b/3", false),
|
|
|
|
newItem("y-c", "c", false),
|
|
|
|
newItem("y-c/", "c/", false),
|
|
|
|
newItem("y-c//", "c//", false),
|
|
|
|
newItem("y-c/1", "c/1", false),
|
|
|
|
newItem("y-g", "g", false),
|
|
|
|
newItem("y-h", "h", false),
|
|
|
|
}
|
|
|
|
rand.Shuffle(len(items), items.Swap)
|
2019-09-24 19:06:22 +01:00
|
|
|
defer cleanupItems(t, ctx, store, items)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-09-24 19:06:22 +01:00
|
|
|
testIterations(t, ctx, store, []iterationTest{
|
2018-09-05 17:10:35 +01:00
|
|
|
{"prefix x dash b slash",
|
|
|
|
storage.IterateOptions{
|
|
|
|
Prefix: storage.Key("x-"), First: storage.Key("x-b"),
|
|
|
|
Recurse: true,
|
|
|
|
}, storage.Items{
|
|
|
|
newItem("x-b/1", "b/1", false),
|
|
|
|
newItem("x-b/2", "b/2", false),
|
|
|
|
newItem("x-b/3", "b/3", false),
|
|
|
|
}},
|
|
|
|
{"prefix x dash b slash",
|
|
|
|
storage.IterateOptions{
|
|
|
|
Prefix: storage.Key("x-"), First: storage.Key("x-b"),
|
|
|
|
}, storage.Items{
|
|
|
|
newItem("x-b/", "", true),
|
|
|
|
}},
|
|
|
|
{"prefix y- slash",
|
|
|
|
storage.IterateOptions{
|
|
|
|
Prefix: storage.Key("y-"),
|
|
|
|
Recurse: true,
|
|
|
|
}, storage.Items{
|
|
|
|
newItem("y-c", "c", false),
|
|
|
|
newItem("y-c/", "c/", false),
|
|
|
|
newItem("y-c//", "c//", false),
|
|
|
|
newItem("y-c/1", "c/1", false),
|
|
|
|
newItem("y-g", "g", false),
|
|
|
|
newItem("y-h", "h", false),
|
|
|
|
}},
|
|
|
|
})
|
|
|
|
}
|