Tests validate the bucket name validator.
(t *testing.T)
| 364 | |
| 365 | // Tests validate the bucket name validator. |
| 366 | func TestIsValidBucketName(t *testing.T) { |
| 367 | testCases := []struct { |
| 368 | // Input. |
| 369 | bucketName string |
| 370 | // Expected result. |
| 371 | err error |
| 372 | // Flag to indicate whether test should Pass. |
| 373 | shouldPass bool |
| 374 | }{ |
| 375 | {".mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 376 | {"$mybucket", errors.New("Bucket name contains invalid characters"), false}, |
| 377 | {"mybucket-", errors.New("Bucket name contains invalid characters"), false}, |
| 378 | {"my", errors.New("Bucket name cannot be shorter than 3 characters"), false}, |
| 379 | {"", errors.New("Bucket name cannot be empty"), false}, |
| 380 | {"my..bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 381 | {"my.-bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 382 | {"my-.bucket", errors.New("Bucket name contains invalid characters"), false}, |
| 383 | {"192.168.1.168", errors.New("Bucket name cannot be an ip address"), false}, |
| 384 | {":bucketname", errors.New("Bucket name contains invalid characters"), false}, |
| 385 | {"_bucketName", errors.New("Bucket name contains invalid characters"), false}, |
| 386 | {"my.bucket.com", nil, true}, |
| 387 | {"my-bucket", nil, true}, |
| 388 | {"123my-bucket", nil, true}, |
| 389 | {"Mybucket", nil, true}, |
| 390 | {"My_bucket", nil, true}, |
| 391 | {"My:bucket", nil, true}, |
| 392 | } |
| 393 | |
| 394 | for i, testCase := range testCases { |
| 395 | err := CheckValidBucketName(testCase.bucketName) |
| 396 | if err != nil && testCase.shouldPass { |
| 397 | t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error()) |
| 398 | } |
| 399 | if err == nil && !testCase.shouldPass { |
| 400 | t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error()) |
| 401 | } |
| 402 | // Failed as expected, but does it fail for the expected reason. |
| 403 | if err != nil && !testCase.shouldPass { |
| 404 | if err.Error() != testCase.err.Error() { |
| 405 | t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error()) |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // Tests validate the bucket name validator stricter. |
| 412 | func TestIsValidBucketNameStrict(t *testing.T) { |
nothing calls this directly
no test coverage detected