github.com/aavshr/aws-sdk-go@v1.41.3/aws/endpoints/decode_test.go (about) 1 package endpoints 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestDecodeEndpoints_V3(t *testing.T) { 9 const v3Doc = ` 10 { 11 "version": 3, 12 "partitions": [ 13 { 14 "defaults": { 15 "hostname": "{service}.{region}.{dnsSuffix}", 16 "protocols": [ 17 "https" 18 ], 19 "signatureVersions": [ 20 "v4" 21 ] 22 }, 23 "dnsSuffix": "amazonaws.com", 24 "partition": "aws", 25 "partitionName": "AWS Standard", 26 "regionRegex": "^(us|eu|ap|sa|ca)\\-\\w+\\-\\d+$", 27 "regions": { 28 "ap-northeast-1": { 29 "description": "Asia Pacific (Tokyo)" 30 } 31 }, 32 "services": { 33 "acm": { 34 "endpoints": { 35 "ap-northeast-1": {} 36 } 37 }, 38 "s3": { 39 "endpoints": { 40 "ap-northeast-1": {} 41 } 42 } 43 } 44 } 45 ] 46 }` 47 48 resolver, err := DecodeModel(strings.NewReader(v3Doc)) 49 if err != nil { 50 t.Fatalf("expected no error, got %v", err) 51 } 52 53 endpoint, err := resolver.EndpointFor("acm", "ap-northeast-1") 54 if err != nil { 55 t.Fatalf("failed to resolve endpoint, %v", err) 56 } 57 58 if a, e := endpoint.URL, "https://acm.ap-northeast-1.amazonaws.com"; a != e { 59 t.Errorf("expected %q URL got %q", e, a) 60 } 61 62 p := resolver.(partitions)[0] 63 64 s3Defaults := p.Services["s3"].Defaults 65 if a, e := s3Defaults.HasDualStack, boxedTrue; a != e { 66 t.Errorf("expect s3 service to have dualstack enabled") 67 } 68 if a, e := s3Defaults.DualStackHostname, "{service}.dualstack.{region}.{dnsSuffix}"; a != e { 69 t.Errorf("expect s3 dualstack host pattern to be %q, got %q", e, a) 70 } 71 } 72 73 func TestDecodeEndpoints_NoPartitions(t *testing.T) { 74 const doc = `{ "version": 3 }` 75 76 resolver, err := DecodeModel(strings.NewReader(doc)) 77 if err == nil { 78 t.Fatalf("expected error") 79 } 80 81 if resolver != nil { 82 t.Errorf("expect resolver to be nil") 83 } 84 } 85 86 func TestDecodeEndpoints_UnsupportedVersion(t *testing.T) { 87 const doc = `{ "version": 2 }` 88 89 resolver, err := DecodeModel(strings.NewReader(doc)) 90 if err == nil { 91 t.Fatalf("expected error decoding model") 92 } 93 94 if resolver != nil { 95 t.Errorf("expect resolver to be nil") 96 } 97 } 98 99 func TestDecodeModelOptionsSet(t *testing.T) { 100 var actual DecodeModelOptions 101 actual.Set(func(o *DecodeModelOptions) { 102 o.SkipCustomizations = true 103 }) 104 105 expect := DecodeModelOptions{ 106 SkipCustomizations: true, 107 } 108 109 if actual != expect { 110 t.Errorf("expect %v options got %v", expect, actual) 111 } 112 } 113 114 func TestCustFixAppAutoscalingChina(t *testing.T) { 115 const doc = ` 116 { 117 "version": 3, 118 "partitions": [{ 119 "defaults" : { 120 "hostname" : "{service}.{region}.{dnsSuffix}", 121 "protocols" : [ "https" ], 122 "signatureVersions" : [ "v4" ] 123 }, 124 "dnsSuffix" : "amazonaws.com.cn", 125 "partition" : "aws-cn", 126 "partitionName" : "AWS China", 127 "regionRegex" : "^cn\\-\\w+\\-\\d+$", 128 "regions" : { 129 "cn-north-1" : { 130 "description" : "China (Beijing)" 131 }, 132 "cn-northwest-1" : { 133 "description" : "China (Ningxia)" 134 } 135 }, 136 "services" : { 137 "application-autoscaling" : { 138 "defaults" : { 139 "credentialScope" : { 140 "service" : "application-autoscaling" 141 }, 142 "hostname" : "autoscaling.{region}.amazonaws.com", 143 "protocols" : [ "http", "https" ] 144 }, 145 "endpoints" : { 146 "cn-north-1" : { }, 147 "cn-northwest-1" : { } 148 } 149 } 150 } 151 }] 152 }` 153 154 resolver, err := DecodeModel(strings.NewReader(doc)) 155 if err != nil { 156 t.Fatalf("expect no error, got %v", err) 157 } 158 159 endpoint, err := resolver.EndpointFor( 160 "application-autoscaling", "cn-northwest-1", 161 ) 162 if err != nil { 163 t.Fatalf("expect no error, got %v", err) 164 } 165 166 if e, a := `https://autoscaling.cn-northwest-1.amazonaws.com.cn`, endpoint.URL; e != a { 167 t.Errorf("expect %v, got %v", e, a) 168 } 169 } 170 171 func TestCustFixAppAutoscalingUsGov(t *testing.T) { 172 const doc = ` 173 { 174 "version": 3, 175 "partitions": [{ 176 "defaults" : { 177 "hostname" : "{service}.{region}.{dnsSuffix}", 178 "protocols" : [ "https" ], 179 "signatureVersions" : [ "v4" ] 180 }, 181 "dnsSuffix" : "amazonaws.com", 182 "partition" : "aws-us-gov", 183 "partitionName" : "AWS GovCloud (US)", 184 "regionRegex" : "^us\\-gov\\-\\w+\\-\\d+$", 185 "regions" : { 186 "us-gov-east-1" : { 187 "description" : "AWS GovCloud (US-East)" 188 }, 189 "us-gov-west-1" : { 190 "description" : "AWS GovCloud (US)" 191 } 192 }, 193 "services" : { 194 "application-autoscaling" : { 195 "endpoints" : { 196 "us-gov-east-1" : { }, 197 "us-gov-west-1" : { } 198 } 199 } 200 } 201 }] 202 }` 203 204 resolver, err := DecodeModel(strings.NewReader(doc)) 205 if err != nil { 206 t.Fatalf("expect no error, got %v", err) 207 } 208 209 endpoint, err := resolver.EndpointFor( 210 "application-autoscaling", "us-gov-west-1", 211 ) 212 if err != nil { 213 t.Fatalf("expect no error, got %v", err) 214 } 215 216 if e, a := `https://autoscaling.us-gov-west-1.amazonaws.com`, endpoint.URL; e != a { 217 t.Errorf("expect %v, got %v", e, a) 218 } 219 }