github.com/aavshr/aws-sdk-go@v1.41.3/aws/endpoints/v3model_test.go (about) 1 //go:build go1.7 2 // +build go1.7 3 4 package endpoints 5 6 import ( 7 "encoding/json" 8 "reflect" 9 "regexp" 10 "strconv" 11 "strings" 12 "testing" 13 ) 14 15 func TestUnmarshalRegionRegex(t *testing.T) { 16 var input = []byte(` 17 { 18 "regionRegex": "^(us|eu|ap|sa|ca)\\-\\w+\\-\\d+$" 19 }`) 20 21 p := partition{} 22 err := json.Unmarshal(input, &p) 23 if err != nil { 24 t.Fatalf("expect no error, got %v", err) 25 } 26 27 expectRegexp, err := regexp.Compile(`^(us|eu|ap|sa|ca)\-\w+\-\d+$`) 28 if err != nil { 29 t.Fatalf("expect no error, got %v", err) 30 } 31 32 if e, a := expectRegexp.String(), p.RegionRegex.Regexp.String(); e != a { 33 t.Errorf("expect %v, got %v", e, a) 34 } 35 } 36 37 func TestUnmarshalRegion(t *testing.T) { 38 var input = []byte(` 39 { 40 "aws-global": { 41 "description": "AWS partition-global endpoint" 42 }, 43 "us-east-1": { 44 "description": "US East (N. Virginia)" 45 } 46 }`) 47 48 rs := regions{} 49 err := json.Unmarshal(input, &rs) 50 if err != nil { 51 t.Fatalf("expect no error, got %v", err) 52 } 53 54 if e, a := 2, len(rs); e != a { 55 t.Errorf("expect %v len, got %v", e, a) 56 } 57 r, ok := rs["aws-global"] 58 if !ok { 59 t.Errorf("expect found, was not") 60 } 61 if e, a := "AWS partition-global endpoint", r.Description; e != a { 62 t.Errorf("expect %v, got %v", e, a) 63 } 64 65 r, ok = rs["us-east-1"] 66 if !ok { 67 t.Errorf("expect found, was not") 68 } 69 if e, a := "US East (N. Virginia)", r.Description; e != a { 70 t.Errorf("expect %v, got %v", e, a) 71 } 72 } 73 74 func TestUnmarshalServices(t *testing.T) { 75 var input = []byte(` 76 { 77 "acm": { 78 "endpoints": { 79 "us-east-1": {} 80 } 81 }, 82 "apigateway": { 83 "isRegionalized": true, 84 "endpoints": { 85 "us-east-1": {}, 86 "us-west-2": {} 87 } 88 }, 89 "notRegionalized": { 90 "isRegionalized": false, 91 "endpoints": { 92 "us-east-1": {}, 93 "us-west-2": {} 94 } 95 } 96 }`) 97 98 ss := services{} 99 err := json.Unmarshal(input, &ss) 100 if err != nil { 101 t.Fatalf("expect no error, got %v", err) 102 } 103 104 if e, a := 3, len(ss); e != a { 105 t.Errorf("expect %v len, got %v", e, a) 106 } 107 s, ok := ss["acm"] 108 if !ok { 109 t.Errorf("expect found, was not") 110 } 111 if e, a := 1, len(s.Endpoints); e != a { 112 t.Errorf("expect %v len, got %v", e, a) 113 } 114 if e, a := boxedBoolUnset, s.IsRegionalized; e != a { 115 t.Errorf("expect %v, got %v", e, a) 116 } 117 118 s, ok = ss["apigateway"] 119 if !ok { 120 t.Errorf("expect found, was not") 121 } 122 if e, a := 2, len(s.Endpoints); e != a { 123 t.Errorf("expect %v len, got %v", e, a) 124 } 125 if e, a := boxedTrue, s.IsRegionalized; e != a { 126 t.Errorf("expect %v, got %v", e, a) 127 } 128 129 s, ok = ss["notRegionalized"] 130 if !ok { 131 t.Errorf("expect found, was not") 132 } 133 if e, a := 2, len(s.Endpoints); e != a { 134 t.Errorf("expect %v len, got %v", e, a) 135 } 136 if e, a := boxedFalse, s.IsRegionalized; e != a { 137 t.Errorf("expect %v, got %v", e, a) 138 } 139 } 140 141 func TestUnmarshalEndpoints(t *testing.T) { 142 var inputs = []byte(` 143 { 144 "aws-global": { 145 "hostname": "cloudfront.amazonaws.com", 146 "protocols": [ 147 "http", 148 "https" 149 ], 150 "signatureVersions": [ "v4" ], 151 "credentialScope": { 152 "region": "us-east-1", 153 "service": "serviceName" 154 }, 155 "sslCommonName": "commonName" 156 }, 157 "us-east-1": {} 158 }`) 159 160 es := endpoints{} 161 err := json.Unmarshal(inputs, &es) 162 if err != nil { 163 t.Fatalf("expect no error, got %v", err) 164 } 165 166 if e, a := 2, len(es); e != a { 167 t.Errorf("expect %v len, got %v", e, a) 168 } 169 s, ok := es["aws-global"] 170 if !ok { 171 t.Errorf("expect found, was not") 172 } 173 if e, a := "cloudfront.amazonaws.com", s.Hostname; e != a { 174 t.Errorf("expect %v, got %v", e, a) 175 } 176 if e, a := []string{"http", "https"}, s.Protocols; !reflect.DeepEqual(e, a) { 177 t.Errorf("expect %v, got %v", e, a) 178 } 179 if e, a := []string{"v4"}, s.SignatureVersions; !reflect.DeepEqual(e, a) { 180 t.Errorf("expect %v, got %v", e, a) 181 } 182 if e, a := (credentialScope{"us-east-1", "serviceName"}), s.CredentialScope; e != a { 183 t.Errorf("expect %v, got %v", e, a) 184 } 185 if e, a := "commonName", s.SSLCommonName; e != a { 186 t.Errorf("expect %v, got %v", e, a) 187 } 188 } 189 190 func TestEndpointResolve(t *testing.T) { 191 defs := []endpoint{ 192 { 193 Hostname: "{service}.{region}.{dnsSuffix}", 194 SignatureVersions: []string{"v2"}, 195 SSLCommonName: "sslCommonName", 196 }, 197 { 198 Hostname: "other-hostname", 199 Protocols: []string{"http"}, 200 CredentialScope: credentialScope{ 201 Region: "signing_region", 202 Service: "signing_service", 203 }, 204 }, 205 } 206 207 e := endpoint{ 208 Hostname: "{service}.{region}.{dnsSuffix}", 209 Protocols: []string{"http", "https"}, 210 SignatureVersions: []string{"v4"}, 211 SSLCommonName: "new sslCommonName", 212 } 213 214 resolved, err := e.resolve("service", "partitionID", "region", "dnsSuffix", 215 defs, Options{}, 216 ) 217 if err != nil { 218 t.Errorf("expected no error, got %v", err) 219 } 220 221 if e, a := "https://service.region.dnsSuffix", resolved.URL; e != a { 222 t.Errorf("expect %v, got %v", e, a) 223 } 224 if e, a := "signing_service", resolved.SigningName; e != a { 225 t.Errorf("expect %v, got %v", e, a) 226 } 227 if e, a := "signing_region", resolved.SigningRegion; e != a { 228 t.Errorf("expect %v, got %v", e, a) 229 } 230 if e, a := "v4", resolved.SigningMethod; e != a { 231 t.Errorf("expect %v, got %v", e, a) 232 } 233 234 // Check Invalid Region Identifier Format 235 _, err = e.resolve("service", "partitionID", "notvalid.com", "dnsSuffix", 236 defs, Options{}, 237 ) 238 if err == nil { 239 t.Errorf("expected err, got nil") 240 } 241 } 242 243 func TestEndpointMergeIn(t *testing.T) { 244 expected := endpoint{ 245 Hostname: "other hostname", 246 Protocols: []string{"http"}, 247 SignatureVersions: []string{"v4"}, 248 SSLCommonName: "ssl common name", 249 CredentialScope: credentialScope{ 250 Region: "region", 251 Service: "service", 252 }, 253 } 254 255 actual := endpoint{} 256 actual.mergeIn(endpoint{ 257 Hostname: "other hostname", 258 Protocols: []string{"http"}, 259 SignatureVersions: []string{"v4"}, 260 SSLCommonName: "ssl common name", 261 CredentialScope: credentialScope{ 262 Region: "region", 263 Service: "service", 264 }, 265 }) 266 267 if e, a := expected, actual; !reflect.DeepEqual(e, a) { 268 t.Errorf("expect %v, got %v", e, a) 269 } 270 } 271 272 func TestResolveEndpoint(t *testing.T) { 273 resolved, err := testPartitions.EndpointFor("service2", "us-west-2") 274 275 if err != nil { 276 t.Fatalf("expect no error, got %v", err) 277 } 278 if e, a := "https://service2.us-west-2.amazonaws.com", resolved.URL; e != a { 279 t.Errorf("expect %v, got %v", e, a) 280 } 281 if e, a := "us-west-2", resolved.SigningRegion; e != a { 282 t.Errorf("expect %v, got %v", e, a) 283 } 284 if e, a := "service2", resolved.SigningName; e != a { 285 t.Errorf("expect %v, got %v", e, a) 286 } 287 if resolved.SigningNameDerived { 288 t.Errorf("expect the signing name not to be derived, but was") 289 } 290 } 291 292 func TestResolveEndpoint_DisableSSL(t *testing.T) { 293 resolved, err := testPartitions.EndpointFor("service2", "us-west-2", DisableSSLOption) 294 295 if err != nil { 296 t.Fatalf("expect no error, got %v", err) 297 } 298 if e, a := "http://service2.us-west-2.amazonaws.com", resolved.URL; e != a { 299 t.Errorf("expect %v, got %v", e, a) 300 } 301 if e, a := "us-west-2", resolved.SigningRegion; e != a { 302 t.Errorf("expect %v, got %v", e, a) 303 } 304 if e, a := "service2", resolved.SigningName; e != a { 305 t.Errorf("expect %v, got %v", e, a) 306 } 307 if resolved.SigningNameDerived { 308 t.Errorf("expect the signing name not to be derived, but was") 309 } 310 } 311 312 func TestResolveEndpoint_UseDualStack(t *testing.T) { 313 resolved, err := testPartitions.EndpointFor("service1", "us-west-2", UseDualStackOption) 314 315 if err != nil { 316 t.Fatalf("expect no error, got %v", err) 317 } 318 if e, a := "https://service1.dualstack.us-west-2.amazonaws.com", resolved.URL; e != a { 319 t.Errorf("expect %v, got %v", e, a) 320 } 321 if e, a := "us-west-2", resolved.SigningRegion; e != a { 322 t.Errorf("expect %v, got %v", e, a) 323 } 324 if e, a := "service1", resolved.SigningName; e != a { 325 t.Errorf("expect %v, got %v", e, a) 326 } 327 if resolved.SigningNameDerived { 328 t.Errorf("expect the signing name not to be derived, but was") 329 } 330 } 331 332 func TestResolveEndpoint_HTTPProtocol(t *testing.T) { 333 resolved, err := testPartitions.EndpointFor("httpService", "us-west-2") 334 335 if err != nil { 336 t.Fatalf("expect no error, got %v", err) 337 } 338 if e, a := "http://httpService.us-west-2.amazonaws.com", resolved.URL; e != a { 339 t.Errorf("expect %v, got %v", e, a) 340 } 341 if e, a := "us-west-2", resolved.SigningRegion; e != a { 342 t.Errorf("expect %v, got %v", e, a) 343 } 344 if e, a := "httpService", resolved.SigningName; e != a { 345 t.Errorf("expect %v, got %v", e, a) 346 } 347 if !resolved.SigningNameDerived { 348 t.Errorf("expect the signing name to be derived") 349 } 350 } 351 352 func TestResolveEndpoint_UnknownService(t *testing.T) { 353 _, err := testPartitions.EndpointFor("unknownservice", "us-west-2") 354 355 if err == nil { 356 t.Errorf("expect error, got none") 357 } 358 359 _, ok := err.(UnknownServiceError) 360 if !ok { 361 t.Errorf("expect error to be UnknownServiceError") 362 } 363 } 364 365 func TestResolveEndpoint_ResolveUnknownService(t *testing.T) { 366 resolved, err := testPartitions.EndpointFor("unknown-service", "us-region-1", 367 ResolveUnknownServiceOption) 368 369 if err != nil { 370 t.Fatalf("expect no error, got %v", err) 371 } 372 373 if e, a := "https://unknown-service.us-region-1.amazonaws.com", resolved.URL; e != a { 374 t.Errorf("expect %v, got %v", e, a) 375 } 376 if e, a := "us-region-1", resolved.SigningRegion; e != a { 377 t.Errorf("expect %v, got %v", e, a) 378 } 379 if e, a := "unknown-service", resolved.SigningName; e != a { 380 t.Errorf("expect %v, got %v", e, a) 381 } 382 if !resolved.SigningNameDerived { 383 t.Errorf("expect the signing name to be derived") 384 } 385 } 386 387 func TestResolveEndpoint_UnknownMatchedRegion(t *testing.T) { 388 resolved, err := testPartitions.EndpointFor("service2", "us-region-1") 389 390 if err != nil { 391 t.Fatalf("expect no error, got %v", err) 392 } 393 if e, a := "https://service2.us-region-1.amazonaws.com", resolved.URL; e != a { 394 t.Errorf("expect %v, got %v", e, a) 395 } 396 if e, a := "us-region-1", resolved.SigningRegion; e != a { 397 t.Errorf("expect %v, got %v", e, a) 398 } 399 if e, a := "service2", resolved.SigningName; e != a { 400 t.Errorf("expect %v, got %v", e, a) 401 } 402 if resolved.SigningNameDerived { 403 t.Errorf("expect the signing name not to be derived, but was") 404 } 405 } 406 407 func TestResolveEndpoint_UnknownRegion(t *testing.T) { 408 resolved, err := testPartitions.EndpointFor("service2", "unknownregion") 409 410 if err != nil { 411 t.Fatalf("expect no error, got %v", err) 412 } 413 if e, a := "https://service2.unknownregion.amazonaws.com", resolved.URL; e != a { 414 t.Errorf("expect %v, got %v", e, a) 415 } 416 if e, a := "unknownregion", resolved.SigningRegion; e != a { 417 t.Errorf("expect %v, got %v", e, a) 418 } 419 if e, a := "service2", resolved.SigningName; e != a { 420 t.Errorf("expect %v, got %v", e, a) 421 } 422 if resolved.SigningNameDerived { 423 t.Errorf("expect the signing name not to be derived, but was") 424 } 425 } 426 427 func TestResolveEndpoint_StrictPartitionUnknownEndpoint(t *testing.T) { 428 _, err := testPartitions[0].EndpointFor("service2", "unknownregion", StrictMatchingOption) 429 430 if err == nil { 431 t.Errorf("expect error, got none") 432 } 433 434 _, ok := err.(UnknownEndpointError) 435 if !ok { 436 t.Errorf("expect error to be UnknownEndpointError") 437 } 438 } 439 440 func TestResolveEndpoint_StrictPartitionsUnknownEndpoint(t *testing.T) { 441 _, err := testPartitions.EndpointFor("service2", "us-region-1", StrictMatchingOption) 442 443 if err == nil { 444 t.Errorf("expect error, got none") 445 } 446 447 _, ok := err.(UnknownEndpointError) 448 if !ok { 449 t.Errorf("expect error to be UnknownEndpointError") 450 } 451 } 452 453 func TestResolveEndpoint_NotRegionalized(t *testing.T) { 454 resolved, err := testPartitions.EndpointFor("globalService", "us-west-2") 455 456 if err != nil { 457 t.Fatalf("expect no error, got %v", err) 458 } 459 if e, a := "https://globalService.amazonaws.com", resolved.URL; e != a { 460 t.Errorf("expect %v, got %v", e, a) 461 } 462 if e, a := "us-east-1", resolved.SigningRegion; e != a { 463 t.Errorf("expect %v, got %v", e, a) 464 } 465 if e, a := "globalService", resolved.SigningName; e != a { 466 t.Errorf("expect %v, got %v", e, a) 467 } 468 if !resolved.SigningNameDerived { 469 t.Errorf("expect the signing name to be derived") 470 } 471 } 472 473 func TestResolveEndpoint_AwsGlobal(t *testing.T) { 474 resolved, err := testPartitions.EndpointFor("globalService", "aws-global") 475 476 if err != nil { 477 t.Fatalf("expect no error, got %v", err) 478 } 479 if e, a := "https://globalService.amazonaws.com", resolved.URL; e != a { 480 t.Errorf("expect %v, got %v", e, a) 481 } 482 if e, a := "us-east-1", resolved.SigningRegion; e != a { 483 t.Errorf("expect %v, got %v", e, a) 484 } 485 if e, a := "globalService", resolved.SigningName; e != a { 486 t.Errorf("expect %v, got %v", e, a) 487 } 488 if !resolved.SigningNameDerived { 489 t.Errorf("expect the signing name to be derived") 490 } 491 } 492 493 func TestEndpointFor_RegionalFlag(t *testing.T) { 494 // AwsPartition resolver for STS regional endpoints in AWS Partition 495 resolver := AwsPartition() 496 497 cases := map[string]struct { 498 service, region string 499 regional bool 500 ExpectURL, ExpectSigningMethod, ExpectSigningRegion string 501 ExpectSigningNameDerived bool 502 }{ 503 "acm/ap-northeast-1/regional": { 504 service: "acm", 505 region: "ap-northeast-1", 506 regional: true, 507 ExpectURL: "https://acm.ap-northeast-1.amazonaws.com", 508 ExpectSigningMethod: "v4", 509 ExpectSigningNameDerived: true, 510 ExpectSigningRegion: "ap-northeast-1", 511 }, 512 "acm/ap-northeast-1/legacy": { 513 service: "acm", 514 region: "ap-northeast-1", 515 regional: false, 516 ExpectURL: "https://acm.ap-northeast-1.amazonaws.com", 517 ExpectSigningMethod: "v4", 518 ExpectSigningNameDerived: true, 519 ExpectSigningRegion: "ap-northeast-1", 520 }, 521 } 522 523 for name, c := range cases { 524 t.Run(name, func(t *testing.T) { 525 var optionSlice []func(o *Options) 526 optionSlice = append(optionSlice, func(o *Options) { 527 if c.regional { 528 o.STSRegionalEndpoint = RegionalSTSEndpoint 529 } 530 }) 531 532 actual, err := resolver.EndpointFor(c.service, c.region, optionSlice...) 533 if err != nil { 534 t.Fatalf("failed to resolve endpoint, %v", err) 535 } 536 537 if e, a := c.ExpectURL, actual.URL; e != a { 538 t.Errorf("expect %v, got %v", e, a) 539 } 540 541 if e, a := c.ExpectSigningMethod, actual.SigningMethod; e != a { 542 t.Errorf("expect %v, got %v", e, a) 543 } 544 545 if e, a := c.ExpectSigningNameDerived, actual.SigningNameDerived; e != a { 546 t.Errorf("expect %v, got %v", e, a) 547 } 548 549 if e, a := c.ExpectSigningRegion, actual.SigningRegion; e != a { 550 t.Errorf("expect %v, got %v", e, a) 551 } 552 553 }) 554 } 555 } 556 557 func TestEndpointFor_EmptyRegion(t *testing.T) { 558 // skip this test for partitions outside `aws` partition 559 if DefaultPartitions()[0].id != "aws" { 560 t.Skip() 561 } 562 563 cases := map[string]struct { 564 Service string 565 Region string 566 RealRegion string 567 ExpectErr string 568 }{ 569 // Legacy services that previous accepted empty region 570 "budgets": {Service: "budgets", RealRegion: "aws-global"}, 571 "ce": {Service: "ce", RealRegion: "aws-global"}, 572 "chime": {Service: "chime", RealRegion: "aws-global"}, 573 "ec2metadata": {Service: "ec2metadata", RealRegion: "aws-global"}, 574 "iam": {Service: "iam", RealRegion: "aws-global"}, 575 "importexport": {Service: "importexport", RealRegion: "aws-global"}, 576 "organizations": {Service: "organizations", RealRegion: "aws-global"}, 577 "route53": {Service: "route53", RealRegion: "aws-global"}, 578 "sts": {Service: "sts", RealRegion: "aws-global"}, 579 "support": {Service: "support", RealRegion: "aws-global"}, 580 "waf": {Service: "waf", RealRegion: "aws-global"}, 581 582 // Other services 583 "s3": {Service: "s3", Region: "us-east-1", RealRegion: "us-east-1"}, 584 "s3 no region": {Service: "s3", ExpectErr: "could not resolve endpoint"}, 585 } 586 587 for name, c := range cases { 588 t.Run(name, func(t *testing.T) { 589 actual, err := DefaultResolver().EndpointFor(c.Service, c.Region) 590 if len(c.ExpectErr) != 0 { 591 if e, a := c.ExpectErr, err.Error(); !strings.Contains(a, e) { 592 t.Errorf("expect %q error in %q", e, a) 593 } 594 return 595 } 596 if err != nil { 597 t.Fatalf("expect no error got, %v", err) 598 } 599 600 expect, err := DefaultResolver().EndpointFor(c.Service, c.RealRegion) 601 if err != nil { 602 t.Fatalf("failed to get endpoint for default resolver") 603 } 604 if e, a := expect.URL, actual.URL; e != a { 605 t.Errorf("expect %v URL, got %v", e, a) 606 } 607 if e, a := expect.SigningRegion, actual.SigningRegion; e != a { 608 t.Errorf("expect %v signing region, got %v", e, a) 609 } 610 611 }) 612 } 613 } 614 615 func TestRegionValidator(t *testing.T) { 616 cases := []struct { 617 Region string 618 Valid bool 619 }{ 620 0: { 621 Region: "us-east-1", 622 Valid: true, 623 }, 624 1: { 625 Region: "invalid.com", 626 Valid: false, 627 }, 628 2: { 629 Region: "@invalid.com/%23", 630 Valid: false, 631 }, 632 3: { 633 Region: "local", 634 Valid: true, 635 }, 636 4: { 637 Region: "9-west-1", 638 Valid: true, 639 }, 640 } 641 642 for i, tt := range cases { 643 t.Run(strconv.Itoa(i), func(t *testing.T) { 644 if e, a := tt.Valid, validateInputRegion(tt.Region); e != a { 645 t.Errorf("expected %v, got %v", e, a) 646 } 647 }) 648 } 649 } 650 651 func TestResolveEndpoint_FipsAwsGlobal(t *testing.T) { 652 resolved, err := testPartitions.EndpointFor("globalService", "fips-aws-global") 653 654 if err != nil { 655 t.Fatalf("expect no error, got %v", err) 656 } 657 if e, a := "https://globalService-fips.amazonaws.com", resolved.URL; e != a { 658 t.Errorf("expect %v, got %v", e, a) 659 } 660 if e, a := "us-east-1", resolved.SigningRegion; e != a { 661 t.Errorf("expect %v, got %v", e, a) 662 } 663 if e, a := "globalService", resolved.SigningName; e != a { 664 t.Errorf("expect %v, got %v", e, a) 665 } 666 if !resolved.SigningNameDerived { 667 t.Errorf("expect the signing name to be derived") 668 } 669 } 670 671 func TestEC2MetadataService(t *testing.T) { 672 unmodelled := partition{ 673 ID: "unmodelled", 674 Name: "partition with unmodelled ec2metadata", 675 Services: map[string]service{ 676 "foo": { 677 Endpoints: endpoints{ 678 "us-west-2": endpoint{ 679 Hostname: "foo.us-west-2.amazonaws.com", 680 Protocols: []string{"http"}, 681 SignatureVersions: []string{"v4"}, 682 }, 683 }, 684 }, 685 }, 686 Regions: map[string]region{ 687 "us-west-2": {Description: "us-west-2 region"}, 688 }, 689 } 690 691 modelled := partition{ 692 ID: "modelled", 693 Name: "partition with modelled ec2metadata", 694 Services: map[string]service{ 695 "ec2metadata": { 696 Endpoints: endpoints{ 697 "us-west-2": endpoint{ 698 Hostname: "custom.localhost/latest", 699 Protocols: []string{"http"}, 700 SignatureVersions: []string{"v4"}, 701 }, 702 }, 703 }, 704 "foo": { 705 Endpoints: endpoints{ 706 "us-west-2": endpoint{ 707 Hostname: "foo.us-west-2.amazonaws.com", 708 Protocols: []string{"http"}, 709 SignatureVersions: []string{"v4"}, 710 }, 711 }, 712 }, 713 }, 714 Regions: map[string]region{ 715 "us-west-2": {Description: "us-west-2 region"}, 716 }, 717 } 718 719 uServices := unmodelled.Partition().Services() 720 721 if s, ok := uServices[Ec2metadataServiceID]; !ok { 722 t.Errorf("expect ec2metadata to be present") 723 } else { 724 if regions := s.Regions(); len(regions) != 0 { 725 t.Errorf("expect no regions for ec2metadata, got %v", len(regions)) 726 } 727 if resolved, err := unmodelled.EndpointFor(Ec2metadataServiceID, "us-west-2"); err != nil { 728 t.Errorf("expect no error, got %v", err) 729 } else if e, a := ec2MetadataEndpointIPv4, resolved.URL; e != a { 730 t.Errorf("expect %v, got %v", e, a) 731 } 732 } 733 734 if s, ok := uServices["foo"]; !ok { 735 t.Errorf("expect foo to be present") 736 } else if regions := s.Regions(); len(regions) == 0 { 737 t.Errorf("expect region endpoints for foo. got none") 738 } 739 740 mServices := modelled.Partition().Services() 741 742 if s, ok := mServices[Ec2metadataServiceID]; !ok { 743 t.Errorf("expect ec2metadata to be present") 744 } else if regions := s.Regions(); len(regions) == 0 { 745 t.Errorf("expect region for ec2metadata, got none") 746 } else { 747 if resolved, err := modelled.EndpointFor(Ec2metadataServiceID, "us-west-2"); err != nil { 748 t.Errorf("expect no error, got %v", err) 749 } else if e, a := "http://custom.localhost/latest", resolved.URL; e != a { 750 t.Errorf("expect %v, got %v", e, a) 751 } 752 } 753 754 if s, ok := mServices["foo"]; !ok { 755 t.Errorf("expect foo to be present") 756 } else if regions := s.Regions(); len(regions) == 0 { 757 t.Errorf("expect region endpoints for foo, got none") 758 } 759 }