Tests validate the bucket name validator stricter.
(t *testing.T)
| 410 | |
| 411 | // Tests validate the bucket name validator stricter. |
| 412 | func TestIsValidBucketNameStrict(t *testing.T) { |
| 413 | testCases := []struct { |
| 414 | // Input. |
| 415 | bucketName string |
| 416 | // Expected result. |
| 417 | err error |
| 418 | // Flag to indicate whether test should Pass. |
| 419 | shouldPass bool |
| 420 | }{ |
| 421 | {".mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 422 | {"$mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 423 | {"mybucket-", errors.New("Bucket name contains invalid characters"), false}, |
| 424 | {"my", errors.New("Bucket name cannot be shorter than 3 characters"), false}, |
| 425 | {"", errors.New("Bucket name cannot be empty"), false}, |
| 426 | {"my..bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 427 | {"my.-bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 428 | {"my-.bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 429 | {"192.168.1.168", errors.New("Bucket name cannot be an ip address"), false}, |
| 430 | {"Mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 431 | {"my.bucket.com", nil, true}, |
| 432 | {"my-bucket", nil, true}, |
| 433 | {"123my-bucket", nil, true}, |
| 434 | } |
| 435 | |
| 436 | for i, testCase := range testCases { |
| 437 | err := CheckValidBucketNameStrict(testCase.bucketName) |
| 438 | if err != nil && testCase.shouldPass { |
| 439 | t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error()) |
| 440 | } |
| 441 | if err == nil && !testCase.shouldPass { |
| 442 | t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error()) |
| 443 | } |
| 444 | // Failed as expected, but does it fail for the expected reason. |
| 445 | if err != nil && !testCase.shouldPass { |
| 446 | if err.Error() != testCase.err.Error() { |
| 447 | t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error()) |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | func TestIsAmazonPrivateLinkEndpoint(t *testing.T) { |
| 454 | testCases := []struct { |
nothing calls this directly
no test coverage detected