Tests validate the bucket name validator.
(t *testing.T)
| 302 | |
| 303 | // Tests validate the bucket name validator. |
| 304 | func TestIsValidBucketName(t *testing.T) { |
| 305 | testCases := []struct { |
| 306 | // Input. |
| 307 | bucketName string |
| 308 | // Expected result. |
| 309 | err error |
| 310 | // Flag to indicate whether test should Pass. |
| 311 | shouldPass bool |
| 312 | }{ |
| 313 | {".mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 314 | {"mybucket.", errors.New("Bucket name contains invalid characters"), false}, |
| 315 | {"mybucket-", errors.New("Bucket name contains invalid characters"), false}, |
| 316 | {"my", errors.New("Bucket name cannot be shorter than 3 characters"), false}, |
| 317 | {"", errors.New("Bucket name cannot be empty"), false}, |
| 318 | {"my..bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 319 | {"my.bucket.com", nil, true}, |
| 320 | {"my-bucket", nil, true}, |
| 321 | {"123my-bucket", nil, true}, |
| 322 | } |
| 323 | |
| 324 | for i, testCase := range testCases { |
| 325 | err := s3utils.CheckValidBucketName(testCase.bucketName) |
| 326 | if err != nil && testCase.shouldPass { |
| 327 | t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error()) |
| 328 | } |
| 329 | if err == nil && !testCase.shouldPass { |
| 330 | t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error()) |
| 331 | } |
| 332 | // Failed as expected, but does it fail for the expected reason. |
| 333 | if err != nil && !testCase.shouldPass { |
| 334 | if err.Error() != testCase.err.Error() { |
| 335 | t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error()) |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // Tests if header is standard supported header |
| 342 | func TestIsStandardHeader(t *testing.T) { |
nothing calls this directly
no test coverage detected