-
Notifications
You must be signed in to change notification settings - Fork 394
/
test_listv2.go
142 lines (132 loc) · 3.37 KB
/
test_listv2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (C) 2019 Storj Labs, Inc.
// 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"
"storj.io/common/testcontext"
"storj.io/storj/storage"
)
func testListV2(t *testing.T, ctx *testcontext.Context, store storage.KeyValueStore) {
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)
defer cleanupItems(t, ctx, store, items)
if err := storage.PutAll(ctx, store, items...); err != nil {
t.Fatalf("failed to setup: %v", err)
}
sort.Sort(items)
type Test struct {
Name string
Options storage.ListOptions
More bool
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 {
got, more, err := storage.ListV2(ctx, store, test.Options)
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)
}
}
}