forked from fastly/go-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_test.go
301 lines (277 loc) · 6.16 KB
/
s3_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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package fastly
import "testing"
func TestClient_S3s(t *testing.T) {
t.Parallel()
var err error
var tv *Version
record(t, "s3s/version", func(c *Client) {
tv = testVersion(t, c)
})
// Create
var s3 *S3
record(t, "s3s/create", func(c *Client) {
s3, err = c.CreateS3(&CreateS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "test-s3",
BucketName: "bucket-name",
Domain: "s3-website-us-west-2.amazonaws.com",
AccessKey: "access_key",
SecretKey: "secret_key",
Path: "/path",
Period: 12,
GzipLevel: 9,
Format: "format",
FormatVersion: 2,
TimestampFormat: "%Y",
Redundancy: S3RedundancyReduced,
})
})
if err != nil {
t.Fatal(err)
}
// Ensure deleted
defer func() {
record(t, "s3s/cleanup", func(c *Client) {
c.DeleteS3(&DeleteS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "test-s3",
})
c.DeleteS3(&DeleteS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "new-test-s3",
})
})
}()
if s3.Name != "test-s3" {
t.Errorf("bad name: %q", s3.Name)
}
if s3.BucketName != "bucket-name" {
t.Errorf("bad bucket_name: %q", s3.BucketName)
}
if s3.AccessKey != "access_key" {
t.Errorf("bad access_key: %q", s3.AccessKey)
}
if s3.SecretKey != "secret_key" {
t.Errorf("bad secret_key: %q", s3.SecretKey)
}
if s3.Domain != "s3-website-us-west-2.amazonaws.com" {
t.Errorf("bad domain: %q", s3.Domain)
}
if s3.Path != "/path" {
t.Errorf("bad path: %q", s3.Path)
}
if s3.Period != 12 {
t.Errorf("bad period: %q", s3.Period)
}
if s3.GzipLevel != 9 {
t.Errorf("bad gzip_level: %q", s3.GzipLevel)
}
if s3.Format != "format" {
t.Errorf("bad format: %q", s3.Format)
}
if s3.FormatVersion != 2 {
t.Errorf("bad format_version: %q", s3.FormatVersion)
}
if s3.TimestampFormat != "%Y" {
t.Errorf("bad timestamp_format: %q", s3.TimestampFormat)
}
if s3.Redundancy != S3RedundancyReduced {
t.Errorf("bad redundancy: %q", s3.Redundancy)
}
// List
var s3s []*S3
record(t, "s3s/list", func(c *Client) {
s3s, err = c.ListS3s(&ListS3sInput{
Service: testServiceID,
Version: tv.Number,
})
})
if err != nil {
t.Fatal(err)
}
if len(s3s) < 1 {
t.Errorf("bad s3s: %v", s3s)
}
// Get
var ns3 *S3
record(t, "s3s/get", func(c *Client) {
ns3, err = c.GetS3(&GetS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "test-s3",
})
})
if err != nil {
t.Fatal(err)
}
if s3.Name != ns3.Name {
t.Errorf("bad name: %q", s3.Name)
}
if s3.BucketName != ns3.BucketName {
t.Errorf("bad bucket_name: %q", s3.BucketName)
}
if s3.AccessKey != ns3.AccessKey {
t.Errorf("bad access_key: %q", s3.AccessKey)
}
if s3.SecretKey != ns3.SecretKey {
t.Errorf("bad secret_key: %q", s3.SecretKey)
}
if s3.Domain != ns3.Domain {
t.Errorf("bad domain: %q", s3.Domain)
}
if s3.Path != ns3.Path {
t.Errorf("bad path: %q", s3.Path)
}
if s3.Period != ns3.Period {
t.Errorf("bad period: %q", s3.Period)
}
if s3.GzipLevel != ns3.GzipLevel {
t.Errorf("bad gzip_level: %q", s3.GzipLevel)
}
if s3.Format != ns3.Format {
t.Errorf("bad format: %q", s3.Format)
}
if s3.FormatVersion != ns3.FormatVersion {
t.Errorf("bad format_version: %q", s3.FormatVersion)
}
if s3.TimestampFormat != ns3.TimestampFormat {
t.Errorf("bad timestamp_format: %q", s3.TimestampFormat)
}
if s3.Redundancy != ns3.Redundancy {
t.Errorf("bad redundancy: %q", s3.Redundancy)
}
// Update
var us3 *S3
record(t, "s3s/update", func(c *Client) {
us3, err = c.UpdateS3(&UpdateS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "test-s3",
NewName: "new-test-s3",
})
})
if err != nil {
t.Fatal(err)
}
if us3.Name != "new-test-s3" {
t.Errorf("bad name: %q", us3.Name)
}
// Delete
record(t, "s3s/delete", func(c *Client) {
err = c.DeleteS3(&DeleteS3Input{
Service: testServiceID,
Version: tv.Number,
Name: "new-test-s3",
})
})
if err != nil {
t.Fatal(err)
}
}
func TestClient_ListS3s_validation(t *testing.T) {
var err error
_, err = testClient.ListS3s(&ListS3sInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.ListS3s(&ListS3sInput{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
}
func TestClient_CreateS3_validation(t *testing.T) {
var err error
_, err = testClient.CreateS3(&CreateS3Input{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.CreateS3(&CreateS3Input{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
}
func TestClient_GetS3_validation(t *testing.T) {
var err error
_, err = testClient.GetS3(&GetS3Input{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetS3(&GetS3Input{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetS3(&GetS3Input{
Service: "foo",
Version: "1",
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}
func TestClient_UpdateS3_validation(t *testing.T) {
var err error
_, err = testClient.UpdateS3(&UpdateS3Input{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.UpdateS3(&UpdateS3Input{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.UpdateS3(&UpdateS3Input{
Service: "foo",
Version: "1",
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}
func TestClient_DeleteS3_validation(t *testing.T) {
var err error
err = testClient.DeleteS3(&DeleteS3Input{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteS3(&DeleteS3Input{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteS3(&DeleteS3Input{
Service: "foo",
Version: "1",
Name: "",
})
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}
}