| 1 |
package fastly |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestClient_S3s(t *testing.T) { |
| 6 |
t.Parallel() |
| 7 |
|
| 8 |
var err error |
| 9 |
var tv *Version |
| 10 |
record(t, "s3s/version", func(c *Client) { |
| 11 |
tv = testVersion(t, c) |
| 12 |
}) |
| 13 |
|
| 14 |
// Create |
| 15 |
var s3 *S3 |
| 16 |
record(t, "s3s/create", func(c *Client) { |
| 17 |
s3, err = c.CreateS3(&CreateS3Input{ |
| 18 |
Service: testServiceID, |
| 19 |
Version: tv.Number, |
| 20 |
Name: "test-s3", |
| 21 |
BucketName: "bucket-name", |
| 22 |
Domain: "s3.us-east-1.amazonaws.com", |
| 23 |
AccessKey: "AKIAIOSFODNN7EXAMPLE", |
| 24 |
SecretKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", |
| 25 |
Path: "/path", |
| 26 |
Period: 12, |
| 27 |
GzipLevel: 9, |
| 28 |
Format: "format", |
| 29 |
FormatVersion: 2, |
| 30 |
TimestampFormat: "%Y", |
| 31 |
MessageType: "classic", |
| 32 |
Redundancy: S3RedundancyReduced, |
| 33 |
Placement: "waf_debug", |
| 34 |
}) |
| 35 |
}) |
| 36 |
if err != nil { |
| 37 |
t.Fatal(err) |
| 38 |
} |
| 39 |
|
| 40 |
// Ensure deleted |
| 41 |
defer func() { |
| 42 |
record(t, "s3s/cleanup", func(c *Client) { |
| 43 |
c.DeleteS3(&DeleteS3Input{ |
| 44 |
Service: testServiceID, |
| 45 |
Version: tv.Number, |
| 46 |
Name: "test-s3", |
| 47 |
}) |
| 48 |
|
| 49 |
c.DeleteS3(&DeleteS3Input{ |
| 50 |
Service: testServiceID, |
| 51 |
Version: tv.Number, |
| 52 |
Name: "new-test-s3", |
| 53 |
}) |
| 54 |
}) |
| 55 |
}() |
| 56 |
|
| 57 |
if s3.Name != "test-s3" { |
| 58 |
t.Errorf("bad name: %q", s3.Name) |
| 59 |
} |
| 60 |
if s3.BucketName != "bucket-name" { |
| 61 |
t.Errorf("bad bucket_name: %q", s3.BucketName) |
| 62 |
} |
| 63 |
if s3.AccessKey != "AKIAIOSFODNN7EXAMPLE" { |
| 64 |
t.Errorf("bad access_key: %q", s3.AccessKey) |
| 65 |
} |
| 66 |
if s3.SecretKey != "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" { |
| 67 |
t.Errorf("bad secret_key: %q", s3.SecretKey) |
| 68 |
} |
| 69 |
if s3.Domain != "s3.us-east-1.amazonaws.com" { |
| 70 |
t.Errorf("bad domain: %q", s3.Domain) |
| 71 |
} |
| 72 |
if s3.Path != "/path" { |
| 73 |
t.Errorf("bad path: %q", s3.Path) |
| 74 |
} |
| 75 |
if s3.Period != 12 { |
| 76 |
t.Errorf("bad period: %q", s3.Period) |
| 77 |
} |
| 78 |
if s3.GzipLevel != 9 { |
| 79 |
t.Errorf("bad gzip_level: %q", s3.GzipLevel) |
| 80 |
} |
| 81 |
if s3.Format != "format" { |
| 82 |
t.Errorf("bad format: %q", s3.Format) |
| 83 |
} |
| 84 |
if s3.FormatVersion != 2 { |
| 85 |
t.Errorf("bad format_version: %q", s3.FormatVersion) |
| 86 |
} |
| 87 |
if s3.TimestampFormat != "%Y" { |
| 88 |
t.Errorf("bad timestamp_format: %q", s3.TimestampFormat) |
| 89 |
} |
| 90 |
if s3.Redundancy != S3RedundancyReduced { |
| 91 |
t.Errorf("bad redundancy: %q", s3.Redundancy) |
| 92 |
} |
| 93 |
if s3.MessageType != "classic" { |
| 94 |
t.Errorf("bad message_type: %q", s3.MessageType) |
| 95 |
} |
| 96 |
if s3.Placement != "waf_debug" { |
| 97 |
t.Errorf("bad placement: %q", s3.Placement) |
| 98 |
} |
| 99 |
|
| 100 |
// List |
| 101 |
var s3s []*S3 |
| 102 |
record(t, "s3s/list", func(c *Client) { |
| 103 |
s3s, err = c.ListS3s(&ListS3sInput{ |
| 104 |
Service: testServiceID, |
| 105 |
Version: tv.Number, |
| 106 |
}) |
| 107 |
}) |
| 108 |
if err != nil { |
| 109 |
t.Fatal(err) |
| 110 |
} |
| 111 |
if len(s3s) < 1 { |
| 112 |
t.Errorf("bad s3s: %v", s3s) |
| 113 |
} |
| 114 |
|
| 115 |
// Get |
| 116 |
var ns3 *S3 |
| 117 |
record(t, "s3s/get", func(c *Client) { |
| 118 |
ns3, err = c.GetS3(&GetS3Input{ |
| 119 |
Service: testServiceID, |
| 120 |
Version: tv.Number, |
| 121 |
Name: "test-s3", |
| 122 |
}) |
| 123 |
}) |
| 124 |
if err != nil { |
| 125 |
t.Fatal(err) |
| 126 |
} |
| 127 |
if s3.Name != ns3.Name { |
| 128 |
t.Errorf("bad name: %q", s3.Name) |
| 129 |
} |
| 130 |
if s3.BucketName != ns3.BucketName { |
| 131 |
t.Errorf("bad bucket_name: %q", s3.BucketName) |
| 132 |
} |
| 133 |
if s3.AccessKey != ns3.AccessKey { |
| 134 |
t.Errorf("bad access_key: %q", s3.AccessKey) |
| 135 |
} |
| 136 |
if s3.SecretKey != ns3.SecretKey { |
| 137 |
t.Errorf("bad secret_key: %q", s3.SecretKey) |
| 138 |
} |
| 139 |
if s3.Domain != ns3.Domain { |
| 140 |
t.Errorf("bad domain: %q", s3.Domain) |
| 141 |
} |
| 142 |
if s3.Path != ns3.Path { |
| 143 |
t.Errorf("bad path: %q", s3.Path) |
| 144 |
} |
| 145 |
if s3.Period != ns3.Period { |
| 146 |
t.Errorf("bad period: %q", s3.Period) |
| 147 |
} |
| 148 |
if s3.GzipLevel != ns3.GzipLevel { |
| 149 |
t.Errorf("bad gzip_level: %q", s3.GzipLevel) |
| 150 |
} |
| 151 |
if s3.Format != ns3.Format { |
| 152 |
t.Errorf("bad format: %q", s3.Format) |
| 153 |
} |
| 154 |
if s3.FormatVersion != ns3.FormatVersion { |
| 155 |
t.Errorf("bad format_version: %q", s3.FormatVersion) |
| 156 |
} |
| 157 |
if s3.TimestampFormat != ns3.TimestampFormat { |
| 158 |
t.Errorf("bad timestamp_format: %q", s3.TimestampFormat) |
| 159 |
} |
| 160 |
if s3.Redundancy != ns3.Redundancy { |
| 161 |
t.Errorf("bad redundancy: %q", s3.Redundancy) |
| 162 |
} |
| 163 |
if s3.Placement != ns3.Placement { |
| 164 |
t.Errorf("bad placement: %q", s3.Placement) |
| 165 |
} |
| 166 |
|
| 167 |
// Update |
| 168 |
var us3 *S3 |
| 169 |
record(t, "s3s/update", func(c *Client) { |
| 170 |
us3, err = c.UpdateS3(&UpdateS3Input{ |
| 171 |
Service: testServiceID, |
| 172 |
Version: tv.Number, |
| 173 |
Name: "test-s3", |
| 174 |
NewName: "new-test-s3", |
| 175 |
}) |
| 176 |
}) |
| 177 |
if err != nil { |
| 178 |
t.Fatal(err) |
| 179 |
} |
| 180 |
if us3.Name != "new-test-s3" { |
| 181 |
t.Errorf("bad name: %q", us3.Name) |
| 182 |
} |
| 183 |
|
| 184 |
// Delete |
| 185 |
record(t, "s3s/delete", func(c *Client) { |
| 186 |
err = c.DeleteS3(&DeleteS3Input{ |
| 187 |
Service: testServiceID, |
| 188 |
Version: tv.Number, |
| 189 |
Name: "new-test-s3", |
| 190 |
}) |
| 191 |
}) |
| 192 |
if err != nil { |
| 193 |
t.Fatal(err) |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
func TestClient_ListS3s_validation(t *testing.T) { |
| 198 |
var err error |
| 199 |
_, err = testClient.ListS3s(&ListS3sInput{ |
| 200 |
Service: "", |
| 201 |
}) |
| 202 |
if err != ErrMissingService { |
| 203 |
t.Errorf("bad error: %s", err) |
| 204 |
} |
| 205 |
|
| 206 |
_, err = testClient.ListS3s(&ListS3sInput{ |
| 207 |
Service: "foo", |
| 208 |
Version: 0, |
| 209 |
}) |
| 210 |
if err != ErrMissingVersion { |
| 211 |
t.Errorf("bad error: %s", err) |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
func TestClient_CreateS3_validation(t *testing.T) { |
| 216 |
var err error |
| 217 |
_, err = testClient.CreateS3(&CreateS3Input{ |
| 218 |
Service: "", |
| 219 |
}) |
| 220 |
if err != ErrMissingService { |
| 221 |
t.Errorf("bad error: %s", err) |
| 222 |
} |
| 223 |
|
| 224 |
_, err = testClient.CreateS3(&CreateS3Input{ |
| 225 |
Service: "foo", |
| 226 |
Version: 0, |
| 227 |
}) |
| 228 |
if err != ErrMissingVersion { |
| 229 |
t.Errorf("bad error: %s", err) |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
func TestClient_GetS3_validation(t *testing.T) { |
| 234 |
var err error |
| 235 |
_, err = testClient.GetS3(&GetS3Input{ |
| 236 |
Service: "", |
| 237 |
}) |
| 238 |
if err != ErrMissingService { |
| 239 |
t.Errorf("bad error: %s", err) |
| 240 |
} |
| 241 |
|
| 242 |
_, err = testClient.GetS3(&GetS3Input{ |
| 243 |
Service: "foo", |
| 244 |
Version: 0, |
| 245 |
}) |
| 246 |
if err != ErrMissingVersion { |
| 247 |
t.Errorf("bad error: %s", err) |
| 248 |
} |
| 249 |
|
| 250 |
_, err = testClient.GetS3(&GetS3Input{ |
| 251 |
Service: "foo", |
| 252 |
Version: 1, |
| 253 |
Name: "", |
| 254 |
}) |
| 255 |
if err != ErrMissingName { |
| 256 |
t.Errorf("bad error: %s", err) |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
func TestClient_UpdateS3_validation(t *testing.T) { |
| 261 |
var err error |
| 262 |
_, err = testClient.UpdateS3(&UpdateS3Input{ |
| 263 |
Service: "", |
| 264 |
}) |
| 265 |
if err != ErrMissingService { |
| 266 |
t.Errorf("bad error: %s", err) |
| 267 |
} |
| 268 |
|
| 269 |
_, err = testClient.UpdateS3(&UpdateS3Input{ |
| 270 |
Service: "foo", |
| 271 |
Version: 0, |
| 272 |
}) |
| 273 |
if err != ErrMissingVersion { |
| 274 |
t.Errorf("bad error: %s", err) |
| 275 |
} |
| 276 |
|
| 277 |
_, err = testClient.UpdateS3(&UpdateS3Input{ |
| 278 |
Service: "foo", |
| 279 |
Version: 1, |
| 280 |
Name: "", |
| 281 |
}) |
| 282 |
if err != ErrMissingName { |
| 283 |
t.Errorf("bad error: %s", err) |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
func TestClient_DeleteS3_validation(t *testing.T) { |
| 288 |
var err error |
| 289 |
err = testClient.DeleteS3(&DeleteS3Input{ |
| 290 |
Service: "", |
| 291 |
}) |
| 292 |
if err != ErrMissingService { |
| 293 |
t.Errorf("bad error: %s", err) |
| 294 |
} |
| 295 |
|
| 296 |
err = testClient.DeleteS3(&DeleteS3Input{ |
| 297 |
Service: "foo", |
| 298 |
Version: 0, |
| 299 |
}) |
| 300 |
if err != ErrMissingVersion { |
| 301 |
t.Errorf("bad error: %s", err) |
| 302 |
} |
| 303 |
|
| 304 |
err = testClient.DeleteS3(&DeleteS3Input{ |
| 305 |
Service: "foo", |
| 306 |
Version: 1, |
| 307 |
Name: "", |
| 308 |
}) |
| 309 |
if err != ErrMissingName { |
| 310 |
t.Errorf("bad error: %s", err) |
| 311 |
} |
| 312 |
} |