|
4 | 4 | "encoding/json" |
5 | 5 | "reflect" |
6 | 6 | "regexp" |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 | ) |
9 | 10 |
|
@@ -522,3 +523,46 @@ func TestResolveEndpoint_AwsGlobal(t *testing.T) { |
522 | 523 | t.Errorf("expect the signing name to be derived") |
523 | 524 | } |
524 | 525 | } |
| 526 | + |
| 527 | +func TestEndpointFor_EmptyRegion(t *testing.T) { |
| 528 | + cases := map[string]struct { |
| 529 | + Service string |
| 530 | + Region string |
| 531 | + RealRegion string |
| 532 | + ExpectErr string |
| 533 | + }{ |
| 534 | + // Legacy services that previous accepted empty region |
| 535 | + "ec2metadata": {Service: "ec2metadata", RealRegion: "aws-global"}, |
| 536 | + |
| 537 | + // Other services |
| 538 | + "s3": {Service: "s3", Region: "us-east-1", RealRegion: "us-east-1"}, |
| 539 | + "s3 no region": {Service: "s3", ExpectErr: "could not resolve endpoint"}, |
| 540 | + } |
| 541 | + |
| 542 | + for name, c := range cases { |
| 543 | + t.Run(name, func(t *testing.T) { |
| 544 | + actual, err := NewDefaultResolver().ResolveEndpoint(c.Service, c.Region) |
| 545 | + if len(c.ExpectErr) != 0 { |
| 546 | + if e, a := c.ExpectErr, err.Error(); !strings.Contains(a, e) { |
| 547 | + t.Errorf("expect %q error in %q", e, a) |
| 548 | + } |
| 549 | + return |
| 550 | + } |
| 551 | + if err != nil { |
| 552 | + t.Fatalf("expect no error got, %v", err) |
| 553 | + } |
| 554 | + |
| 555 | + expect, err := NewDefaultResolver().ResolveEndpoint(c.Service, c.RealRegion) |
| 556 | + if err != nil { |
| 557 | + t.Fatalf("failed to get endpoint for default resolver") |
| 558 | + } |
| 559 | + if e, a := expect.URL, actual.URL; e != a { |
| 560 | + t.Errorf("expect %v URL, got %v", e, a) |
| 561 | + } |
| 562 | + if e, a := expect.SigningRegion, actual.SigningRegion; e != a { |
| 563 | + t.Errorf("expect %v signing region, got %v", e, a) |
| 564 | + } |
| 565 | + |
| 566 | + }) |
| 567 | + } |
| 568 | +} |
0 commit comments