-
Notifications
You must be signed in to change notification settings - Fork 84
/
uploader_test.go
171 lines (132 loc) · 5.48 KB
/
uploader_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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package gofakes3_test
import (
"testing"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/johannesboyne/gofakes3"
)
func TestMultipartUpload(t *testing.T) {
const size = defaultUploadPartSize
for _, tc := range []struct {
parts int64 // number of parts
size int64 // size of all parts but last
last int64 // size of last part; if 0, size is used
}{
{parts: 1, size: size, last: 0},
{parts: 10, size: size, last: 1},
{parts: 2, size: 20 * 1024 * 1024, last: (20 * 1024 * 1024) - 1},
// FIXME: Unfortunately, larger tests are too slow to be practical on
// every run; should be skipped by default and enabled with a flag
// later:
// {parts: 100, size: 10 * 1024 * 1024, last: 1},
} {
t.Run("", func(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
var size int64
if tc.last == 0 {
size = tc.parts * tc.size
} else {
size = (tc.parts-1)*tc.size + tc.last
}
body := randomFileBody(size)
ts.assertMultipartUpload(defaultBucket, "uploadtest", body, nil)
})
}
}
func TestAbortMultipartUpload(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
ts.createMultipartUpload(defaultBucket, "obj", nil)
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Uploads: strs("obj/1")})
ts.assertAbortMultipartUpload(defaultBucket, "obj", "1")
}
func TestListMultipartUploadsWithTheSameObjectKey(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
ts.createMultipartUpload(defaultBucket, "obj", nil)
ts.createMultipartUpload(defaultBucket, "obj", nil)
ts.createMultipartUpload(defaultBucket, "obj", nil)
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Uploads: strs("obj/1", "obj/2", "obj/3")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Limit: 1, Uploads: strs("obj/1")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Limit: 2, Uploads: strs("obj/1", "obj/2")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Marker: "obj/2", Limit: 1, Uploads: strs("obj/2")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Marker: "obj/2", Limit: 2, Uploads: strs("obj/2", "obj/3")})
}
func TestListMultipartUploadsWithDifferentObjectKeys(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
ts.createMultipartUpload(defaultBucket, "foo", nil)
ts.createMultipartUpload(defaultBucket, "bar", nil)
ts.createMultipartUpload(defaultBucket, "baz", nil)
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Uploads: strs("bar/2", "baz/3", "foo/1")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Limit: 1, Uploads: strs("bar/2")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Limit: 2, Uploads: strs("bar/2", "baz/3")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Marker: "baz/3", Limit: 1, Uploads: strs("baz/3")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Marker: "baz/3", Limit: 2, Uploads: strs("baz/3", "foo/1")})
}
func TestListMultipartUploadsPrefix(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
ts.createMultipartUpload(defaultBucket, "foo/bar", nil)
ts.createMultipartUpload(defaultBucket, "foo/bar", nil)
ts.createMultipartUpload(defaultBucket, "foo/baz", nil)
ts.createMultipartUpload(defaultBucket, "foo/nested/yep", nil)
ts.createMultipartUpload(defaultBucket, "food/bar", nil)
ts.createMultipartUpload(defaultBucket, "food/baz", nil)
ts.createMultipartUpload(defaultBucket, "yep/qux", nil)
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{Prefix: prefixFile("/"),
Prefixes: strs("foo/", "food/", "yep/")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{Prefix: prefixFile("fo"),
Prefixes: strs("foo/", "food/")})
// No prefix gives you everything:
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Uploads: strs("foo/bar/1", "foo/bar/2", "foo/baz/3", "foo/nested/yep/4", "food/bar/5", "food/baz/6", "yep/qux/7")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{
Limit: 3,
Uploads: strs("foo/bar/1", "foo/bar/2", "foo/baz/3")})
ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{Prefix: prefixFile("foo/"),
Prefixes: strs("foo/nested/"),
Uploads: strs("foo/bar/1", "foo/bar/2", "foo/baz/3")})
// FIXME: This requires further investigation. How does AWS treat the combination
// of commonprefixes and a limit?
// ts.assertListMultipartUploads(defaultBucket, listUploadsOpts{Prefix: prefixFile("foo/"),
// Limit: 2,
// Prefixes: strs("foo/nested/"),
// Uploads: strs("foo/bar/1", "foo/bar/2")})
}
func TestListMultipartUploadParts(t *testing.T) {
doUpload := func(ts *testServer) {
id := ts.createMultipartUpload(defaultBucket, "foo", nil)
parts := []*s3.CompletedPart{
ts.uploadPart(defaultBucket, "foo", id, 1, []byte("abc")),
ts.uploadPart(defaultBucket, "foo", id, 2, []byte("def")),
ts.uploadPart(defaultBucket, "foo", id, 3, []byte("ghi")),
}
ts.assertListUploadParts(defaultBucket, "foo", id,
listUploadPartsOpts{}.withCompletedParts(parts...))
ts.assertCompleteUpload(defaultBucket, "foo", id, parts, []byte("abcdefghi"))
// No parts should be returned after the upload is completed:
ts.assertListUploadPartsFails(gofakes3.ErrNoSuchUpload, defaultBucket, "foo", id, listUploadPartsOpts{})
}
t.Run("location: HostBucket", func(t *testing.T) {
ts := newTestServer(t, withHostBucket())
defer ts.Close()
doUpload(ts)
})
t.Run("location: PathBucket", func(t *testing.T) {
ts := newTestServer(t)
defer ts.Close()
doUpload(ts)
})
}