1 package endpoints
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestEndpointResolve(t *testing.T) {
9 defs := Endpoint{
10 Hostname: "service.{region}.amazonaws.com",
11 SignatureVersions: []string{"v4"},
12 }
13
14 e := Endpoint{
15 Protocols: []string{"http", "https"},
16 SignatureVersions: []string{"v4"},
17 CredentialScope: CredentialScope{
18 Region: "us-west-2",
19 Service: "service",
20 },
21 }
22
23 resolved, err := e.resolve("aws", "us-west-2", defs, Options{})
24 if err != nil {
25 t.Errorf("expect no error, got %v", err)
26 }
27
28 if e, a := "https://service.us-west-2.amazonaws.com", resolved.URL; e != a {
29 t.Errorf("expect %v, got %v", e, a)
30 }
31 if e, a := "aws", resolved.PartitionID; e != a {
32 t.Errorf("expect %v, got %v", e, a)
33 }
34 if e, a := "service", resolved.SigningName; e != a {
35 t.Errorf("expect %v, got %v", e, a)
36 }
37 if e, a := "us-west-2", resolved.SigningRegion; e != a {
38 t.Errorf("expect %v, got %v", e, a)
39 }
40 if e, a := "v4", resolved.SigningMethod; e != a {
41 t.Errorf("expect %v, got %v", e, a)
42 }
43 }
44
45 func TestEndpointMergeIn(t *testing.T) {
46 expected := Endpoint{
47 Hostname: "other hostname",
48 Protocols: []string{"http"},
49 SignatureVersions: []string{"v4"},
50 CredentialScope: CredentialScope{
51 Region: "region",
52 Service: "service",
53 },
54 }
55
56 actual := Endpoint{}
57 actual.mergeIn(Endpoint{
58 Hostname: "other hostname",
59 Protocols: []string{"http"},
60 SignatureVersions: []string{"v4"},
61 CredentialScope: CredentialScope{
62 Region: "region",
63 Service: "service",
64 },
65 })
66
67 if e, a := expected, actual; !reflect.DeepEqual(e, a) {
68 t.Errorf("expect %v, got %v", e, a)
69 }
70 }
71
View as plain text