forked from rlmcpherson/s3gof3r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_objects_test.go
85 lines (72 loc) · 1.71 KB
/
list_objects_test.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
package s3gof3r
import (
"log"
"sort"
"sync"
"testing"
)
var keysForListing = []string{
"list/one/two/three",
"list/one/two/four",
"list/two/three/four",
"list/two/three/five",
"list/three/four/five",
"list/three/four/six",
"list/four/five/six",
"list/four/five/seven",
}
func uploadListerFiles() {
var wg sync.WaitGroup
for _, tt := range keysForListing {
wg.Add(1)
go func(path string) {
err := b.putReader(path, &randSrc{Size: 20})
if err != nil {
log.Fatal(err)
}
wg.Done()
}(tt)
}
wg.Wait()
}
func testListObjects(t *testing.T, prefixes []string, iterations, concurrency int) {
config := Config{
Concurrency: 1,
Scheme: "https",
}
l, err := b.ListObjects(prefixes, 5, &config)
if err != nil {
t.Error(err)
}
actual := make([]string, 0, len(keysForListing))
actualIterations := 0
for l.Next() {
actualIterations++
actual = append(actual, l.Value()...)
}
err = l.Error()
if err != nil {
t.Error(err)
}
if actualIterations != iterations {
t.Errorf("expected %d iterations, got %d", iterations, actualIterations)
}
if len(actual) != len(keysForListing) {
t.Errorf("expected %d keys, got %d", len(keysForListing), len(actual))
}
sort.Strings(keysForListing)
sort.Strings(actual)
for i, a := range keysForListing {
if a != actual[i] {
t.Errorf("result mismatch, expected '%s', got '%s'", a, actual[i])
}
}
}
func TestListObjects(t *testing.T) {
t.Parallel()
uploadListerFiles()
testListObjects(t, []string{"list/"}, 2, 1)
testListObjects(t, []string{"list/"}, 2, 5)
testListObjects(t, []string{"list/one/", "list/two/", "list/three", "list/four"}, 4, 1)
testListObjects(t, []string{"list/one/", "list/two/", "list/three", "list/four"}, 4, 5)
}