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"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"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 testListV2(t *testing.T, ctx *testcontext.Context, store storage.KeyValueStore) {
|
2018-09-05 17:10:35 +01:00
|
|
|
items := storage.Items{
|
|
|
|
newItem("music/a-song1.mp3", "1", false),
|
|
|
|
newItem("music/a-song2.mp3", "2", false),
|
|
|
|
newItem("music/my-album/song3.mp3", "3", false),
|
|
|
|
newItem("music/my-album/song4.mp3", "4", false),
|
|
|
|
newItem("music/z-song5.mp3", "5", false),
|
|
|
|
newItem("sample.jpg", "6", false),
|
|
|
|
newItem("videos/movie.mkv", "7", 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
|
|
|
}
|
2018-09-07 15:20:15 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
sort.Sort(items)
|
|
|
|
|
|
|
|
type Test struct {
|
|
|
|
Name string
|
|
|
|
Options storage.ListOptions
|
2018-09-07 15:20:15 +01:00
|
|
|
More bool
|
2018-09-05 17:10:35 +01:00
|
|
|
Expected storage.Items
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []Test{
|
|
|
|
{"all",
|
|
|
|
storage.ListOptions{
|
|
|
|
Recursive: true,
|
|
|
|
IncludeValue: true,
|
|
|
|
},
|
|
|
|
false, items,
|
|
|
|
},
|
|
|
|
{"music",
|
|
|
|
storage.ListOptions{
|
|
|
|
Prefix: storage.Key("music/"),
|
|
|
|
},
|
|
|
|
false, storage.Items{
|
|
|
|
newItem("a-song1.mp3", "", false),
|
|
|
|
newItem("a-song2.mp3", "", false),
|
|
|
|
newItem("my-album/", "", true),
|
|
|
|
newItem("z-song5.mp3", "", false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"music recursive",
|
|
|
|
storage.ListOptions{
|
|
|
|
Recursive: true,
|
|
|
|
Prefix: storage.Key("music/"),
|
|
|
|
},
|
|
|
|
false, storage.Items{
|
|
|
|
newItem("a-song1.mp3", "", false),
|
|
|
|
newItem("a-song2.mp3", "", false),
|
|
|
|
newItem("my-album/song3.mp3", "", false),
|
|
|
|
newItem("my-album/song4.mp3", "", false),
|
|
|
|
newItem("z-song5.mp3", "", false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"all non-recursive without value (default)",
|
|
|
|
storage.ListOptions{},
|
|
|
|
false, storage.Items{
|
|
|
|
newItem("music/", "", true),
|
|
|
|
newItem("sample.jpg", "", false),
|
|
|
|
newItem("videos/", "", true),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"all non-recursive",
|
|
|
|
storage.ListOptions{
|
|
|
|
IncludeValue: true,
|
|
|
|
},
|
|
|
|
false, storage.Items{
|
|
|
|
newItem("music/", "", true),
|
|
|
|
newItem("sample.jpg", "6", false),
|
|
|
|
newItem("videos/", "", true),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"start after 2 recursive",
|
|
|
|
storage.ListOptions{
|
|
|
|
Recursive: true,
|
|
|
|
StartAfter: storage.Key("music/a-song1.mp3"),
|
|
|
|
Limit: 2,
|
|
|
|
},
|
|
|
|
true, storage.Items{
|
|
|
|
newItem("music/a-song2.mp3", "", false),
|
|
|
|
newItem("music/my-album/song3.mp3", "", false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"start after non-existing 2 recursive",
|
|
|
|
storage.ListOptions{
|
|
|
|
Recursive: true,
|
|
|
|
StartAfter: storage.Key("music/a-song15.mp3"),
|
|
|
|
Limit: 2,
|
|
|
|
},
|
|
|
|
true, storage.Items{
|
|
|
|
newItem("music/a-song2.mp3", "", false),
|
|
|
|
newItem("music/my-album/song3.mp3", "", false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"start after 2",
|
|
|
|
storage.ListOptions{
|
|
|
|
Prefix: storage.Key("music/"),
|
|
|
|
StartAfter: storage.Key("a-song1.mp3"),
|
|
|
|
Limit: 2,
|
|
|
|
},
|
|
|
|
true, storage.Items{
|
|
|
|
newItem("a-song2.mp3", "", false),
|
|
|
|
newItem("my-album/", "", true),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2019-06-05 15:23:10 +01:00
|
|
|
got, more, err := storage.ListV2(ctx, store, test.Options)
|
2018-09-05 17:10:35 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%v: %v", test.Name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if more != test.More {
|
|
|
|
t.Errorf("%v: more %v expected %v", test.Name, more, test.More)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(test.Expected, got, cmpopts.EquateEmpty()); diff != "" {
|
|
|
|
t.Errorf("%s: (-want +got)\n%s", test.Name, diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|