github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/cloudfront_distribution_configuration_structure_test.go (about) 1 package aws 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/hashicorp/terraform/helper/schema" 9 ) 10 11 func defaultCacheBehaviorConf() map[string]interface{} { 12 return map[string]interface{}{ 13 "viewer_protocol_policy": "allow-all", 14 "target_origin_id": "myS3Origin", 15 "forwarded_values": schema.NewSet(forwardedValuesHash, []interface{}{forwardedValuesConf()}), 16 "min_ttl": 86400, 17 "trusted_signers": trustedSignersConf(), 18 "max_ttl": 365000000, 19 "smooth_streaming": false, 20 "default_ttl": 86400, 21 "allowed_methods": allowedMethodsConf(), 22 "cached_methods": cachedMethodsConf(), 23 "compress": true, 24 } 25 } 26 27 func cacheBehaviorConf1() map[string]interface{} { 28 cb := defaultCacheBehaviorConf() 29 cb["path_pattern"] = "/path1" 30 return cb 31 } 32 33 func cacheBehaviorConf2() map[string]interface{} { 34 cb := defaultCacheBehaviorConf() 35 cb["path_pattern"] = "/path2" 36 return cb 37 } 38 39 func cacheBehaviorsConf() *schema.Set { 40 return schema.NewSet(cacheBehaviorHash, []interface{}{cacheBehaviorConf1(), cacheBehaviorConf2()}) 41 } 42 43 func trustedSignersConf() []interface{} { 44 return []interface{}{"1234567890EX", "1234567891EX"} 45 } 46 47 func forwardedValuesConf() map[string]interface{} { 48 return map[string]interface{}{ 49 "query_string": true, 50 "query_string_cache_keys": queryStringCacheKeysConf(), 51 "cookies": schema.NewSet(cookiePreferenceHash, []interface{}{cookiePreferenceConf()}), 52 "headers": headersConf(), 53 } 54 } 55 56 func headersConf() []interface{} { 57 return []interface{}{"X-Example1", "X-Example2"} 58 } 59 60 func queryStringCacheKeysConf() []interface{} { 61 return []interface{}{"foo", "bar"} 62 } 63 64 func cookiePreferenceConf() map[string]interface{} { 65 return map[string]interface{}{ 66 "forward": "whitelist", 67 "whitelisted_names": cookieNamesConf(), 68 } 69 } 70 71 func cookieNamesConf() []interface{} { 72 return []interface{}{"Example1", "Example2"} 73 } 74 75 func allowedMethodsConf() []interface{} { 76 return []interface{}{"DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"} 77 } 78 79 func cachedMethodsConf() []interface{} { 80 return []interface{}{"GET", "HEAD", "OPTIONS"} 81 } 82 83 func originCustomHeadersConf() *schema.Set { 84 return schema.NewSet(originCustomHeaderHash, []interface{}{originCustomHeaderConf1(), originCustomHeaderConf2()}) 85 } 86 87 func originCustomHeaderConf1() map[string]interface{} { 88 return map[string]interface{}{ 89 "name": "X-Custom-Header1", 90 "value": "samplevalue", 91 } 92 } 93 94 func originCustomHeaderConf2() map[string]interface{} { 95 return map[string]interface{}{ 96 "name": "X-Custom-Header2", 97 "value": "samplevalue", 98 } 99 } 100 101 func customOriginConf() map[string]interface{} { 102 return map[string]interface{}{ 103 "origin_protocol_policy": "http-only", 104 "http_port": 80, 105 "https_port": 443, 106 "origin_ssl_protocols": customOriginSslProtocolsConf(), 107 } 108 } 109 110 func customOriginSslProtocolsConf() []interface{} { 111 return []interface{}{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"} 112 } 113 114 func s3OriginConf() map[string]interface{} { 115 return map[string]interface{}{ 116 "origin_access_identity": "origin-access-identity/cloudfront/E127EXAMPLE51Z", 117 } 118 } 119 120 func originWithCustomConf() map[string]interface{} { 121 return map[string]interface{}{ 122 "origin_id": "CustomOrigin", 123 "domain_name": "www.example.com", 124 "origin_path": "/", 125 "custom_origin_config": schema.NewSet(customOriginConfigHash, []interface{}{customOriginConf()}), 126 "custom_header": originCustomHeadersConf(), 127 } 128 } 129 func originWithS3Conf() map[string]interface{} { 130 return map[string]interface{}{ 131 "origin_id": "S3Origin", 132 "domain_name": "s3.example.com", 133 "origin_path": "/", 134 "s3_origin_config": schema.NewSet(s3OriginConfigHash, []interface{}{s3OriginConf()}), 135 "custom_header": originCustomHeadersConf(), 136 } 137 } 138 139 func multiOriginConf() *schema.Set { 140 return schema.NewSet(originHash, []interface{}{originWithCustomConf(), originWithS3Conf()}) 141 } 142 143 func geoRestrictionWhitelistConf() map[string]interface{} { 144 return map[string]interface{}{ 145 "restriction_type": "whitelist", 146 "locations": []interface{}{"CA", "GB", "US"}, 147 } 148 } 149 150 func geoRestrictionsConf() map[string]interface{} { 151 return map[string]interface{}{ 152 "geo_restriction": schema.NewSet(geoRestrictionHash, []interface{}{geoRestrictionWhitelistConf()}), 153 } 154 } 155 156 func geoRestrictionConfNoItems() map[string]interface{} { 157 return map[string]interface{}{ 158 "restriction_type": "none", 159 } 160 } 161 162 func customErrorResponsesConf() []interface{} { 163 return []interface{}{ 164 map[string]interface{}{ 165 "error_code": 404, 166 "error_caching_min_ttl": 30, 167 "response_code": 200, 168 "response_page_path": "/error-pages/404.html", 169 }, 170 map[string]interface{}{ 171 "error_code": 403, 172 "error_caching_min_ttl": 15, 173 "response_code": 404, 174 "response_page_path": "/error-pages/404.html", 175 }, 176 } 177 } 178 179 func aliasesConf() *schema.Set { 180 return schema.NewSet(aliasesHash, []interface{}{"example.com", "www.example.com"}) 181 } 182 183 func loggingConfigConf() map[string]interface{} { 184 return map[string]interface{}{ 185 "include_cookies": false, 186 "bucket": "mylogs.s3.amazonaws.com", 187 "prefix": "myprefix", 188 } 189 } 190 191 func customErrorResponsesConfSet() *schema.Set { 192 return schema.NewSet(customErrorResponseHash, customErrorResponsesConf()) 193 } 194 195 func customErrorResponsesConfFirst() map[string]interface{} { 196 return customErrorResponsesConf()[0].(map[string]interface{}) 197 } 198 199 func customErrorResponseConfNoResponseCode() map[string]interface{} { 200 er := customErrorResponsesConf()[0].(map[string]interface{}) 201 er["response_code"] = 0 202 er["response_page_path"] = "" 203 return er 204 } 205 206 func viewerCertificateConfSetCloudFrontDefault() map[string]interface{} { 207 return map[string]interface{}{ 208 "acm_certificate_arn": "", 209 "cloudfront_default_certificate": true, 210 "iam_certificate_id": "", 211 "minimum_protocol_version": "", 212 "ssl_support_method": "", 213 } 214 } 215 216 func viewerCertificateConfSetIAM() map[string]interface{} { 217 return map[string]interface{}{ 218 "acm_certificate_arn": "", 219 "cloudfront_default_certificate": false, 220 "iam_certificate_id": "iamcert-01234567", 221 "ssl_support_method": "vip", 222 "minimum_protocol_version": "TLSv1", 223 } 224 } 225 226 func viewerCertificateConfSetACM() map[string]interface{} { 227 return map[string]interface{}{ 228 "acm_certificate_arn": "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012", 229 "cloudfront_default_certificate": false, 230 "iam_certificate_id": "", 231 "ssl_support_method": "sni-only", 232 "minimum_protocol_version": "TLSv1", 233 } 234 } 235 236 func TestCloudFrontStructure_expandDefaultCacheBehavior(t *testing.T) { 237 data := defaultCacheBehaviorConf() 238 dcb := expandDefaultCacheBehavior(data) 239 if *dcb.Compress != true { 240 t.Fatalf("Expected Compress to be true, got %v", *dcb.Compress) 241 } 242 if *dcb.ViewerProtocolPolicy != "allow-all" { 243 t.Fatalf("Expected ViewerProtocolPolicy to be allow-all, got %v", *dcb.ViewerProtocolPolicy) 244 } 245 if *dcb.TargetOriginId != "myS3Origin" { 246 t.Fatalf("Expected TargetOriginId to be allow-all, got %v", *dcb.TargetOriginId) 247 } 248 if reflect.DeepEqual(dcb.ForwardedValues.Headers.Items, expandStringList(headersConf())) != true { 249 t.Fatalf("Expected Items to be %v, got %v", headersConf(), dcb.ForwardedValues.Headers.Items) 250 } 251 if *dcb.MinTTL != 86400 { 252 t.Fatalf("Expected MinTTL to be 86400, got %v", *dcb.MinTTL) 253 } 254 if reflect.DeepEqual(dcb.TrustedSigners.Items, expandStringList(trustedSignersConf())) != true { 255 t.Fatalf("Expected TrustedSigners.Items to be %v, got %v", trustedSignersConf(), dcb.TrustedSigners.Items) 256 } 257 if *dcb.MaxTTL != 365000000 { 258 t.Fatalf("Expected MaxTTL to be 365000000, got %v", *dcb.MaxTTL) 259 } 260 if *dcb.SmoothStreaming != false { 261 t.Fatalf("Expected SmoothStreaming to be false, got %v", *dcb.SmoothStreaming) 262 } 263 if *dcb.DefaultTTL != 86400 { 264 t.Fatalf("Expected DefaultTTL to be 86400, got %v", *dcb.DefaultTTL) 265 } 266 if reflect.DeepEqual(dcb.AllowedMethods.Items, expandStringList(allowedMethodsConf())) != true { 267 t.Fatalf("Expected TrustedSigners.Items to be %v, got %v", allowedMethodsConf(), dcb.AllowedMethods.Items) 268 } 269 if reflect.DeepEqual(dcb.AllowedMethods.CachedMethods.Items, expandStringList(cachedMethodsConf())) != true { 270 t.Fatalf("Expected TrustedSigners.Items to be %v, got %v", cachedMethodsConf(), dcb.AllowedMethods.CachedMethods.Items) 271 } 272 } 273 274 func TestCloudFrontStructure_flattenDefaultCacheBehavior(t *testing.T) { 275 in := defaultCacheBehaviorConf() 276 dcb := expandDefaultCacheBehavior(in) 277 out := flattenDefaultCacheBehavior(dcb) 278 diff := schema.NewSet(defaultCacheBehaviorHash, []interface{}{in}).Difference(out) 279 280 if len(diff.List()) > 0 { 281 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 282 } 283 } 284 285 func TestCloudFrontStructure_expandCacheBehavior(t *testing.T) { 286 data := cacheBehaviorConf1() 287 cb := expandCacheBehavior(data) 288 if *cb.Compress != true { 289 t.Fatalf("Expected Compress to be true, got %v", *cb.Compress) 290 } 291 if *cb.ViewerProtocolPolicy != "allow-all" { 292 t.Fatalf("Expected ViewerProtocolPolicy to be allow-all, got %v", *cb.ViewerProtocolPolicy) 293 } 294 if *cb.TargetOriginId != "myS3Origin" { 295 t.Fatalf("Expected TargetOriginId to be myS3Origin, got %v", *cb.TargetOriginId) 296 } 297 if reflect.DeepEqual(cb.ForwardedValues.Headers.Items, expandStringList(headersConf())) != true { 298 t.Fatalf("Expected Items to be %v, got %v", headersConf(), cb.ForwardedValues.Headers.Items) 299 } 300 if *cb.MinTTL != 86400 { 301 t.Fatalf("Expected MinTTL to be 86400, got %v", *cb.MinTTL) 302 } 303 if reflect.DeepEqual(cb.TrustedSigners.Items, expandStringList(trustedSignersConf())) != true { 304 t.Fatalf("Expected TrustedSigners.Items to be %v, got %v", trustedSignersConf(), cb.TrustedSigners.Items) 305 } 306 if *cb.MaxTTL != 365000000 { 307 t.Fatalf("Expected MaxTTL to be 365000000, got %v", *cb.MaxTTL) 308 } 309 if *cb.SmoothStreaming != false { 310 t.Fatalf("Expected SmoothStreaming to be false, got %v", *cb.SmoothStreaming) 311 } 312 if *cb.DefaultTTL != 86400 { 313 t.Fatalf("Expected DefaultTTL to be 86400, got %v", *cb.DefaultTTL) 314 } 315 if reflect.DeepEqual(cb.AllowedMethods.Items, expandStringList(allowedMethodsConf())) != true { 316 t.Fatalf("Expected AllowedMethods.Items to be %v, got %v", allowedMethodsConf(), cb.AllowedMethods.Items) 317 } 318 if reflect.DeepEqual(cb.AllowedMethods.CachedMethods.Items, expandStringList(cachedMethodsConf())) != true { 319 t.Fatalf("Expected AllowedMethods.CachedMethods.Items to be %v, got %v", cachedMethodsConf(), cb.AllowedMethods.CachedMethods.Items) 320 } 321 if *cb.PathPattern != "/path1" { 322 t.Fatalf("Expected PathPattern to be /path1, got %v", *cb.PathPattern) 323 } 324 } 325 326 func TestCloudFrontStructure_flattenCacheBehavior(t *testing.T) { 327 in := cacheBehaviorConf1() 328 cb := expandCacheBehavior(in) 329 out := flattenCacheBehavior(cb) 330 var diff *schema.Set 331 if out["compress"] != true { 332 t.Fatalf("Expected out[compress] to be true, got %v", out["compress"]) 333 } 334 if out["viewer_protocol_policy"] != "allow-all" { 335 t.Fatalf("Expected out[viewer_protocol_policy] to be allow-all, got %v", out["viewer_protocol_policy"]) 336 } 337 if out["target_origin_id"] != "myS3Origin" { 338 t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"]) 339 } 340 diff = out["forwarded_values"].(*schema.Set).Difference(in["forwarded_values"].(*schema.Set)) 341 if len(diff.List()) > 0 { 342 t.Fatalf("Expected out[forwarded_values] to be %v, got %v, diff: %v", out["forwarded_values"], in["forwarded_values"], diff) 343 } 344 if out["min_ttl"] != int(86400) { 345 t.Fatalf("Expected out[min_ttl] to be 86400 (int), got %v", out["forwarded_values"]) 346 } 347 if reflect.DeepEqual(out["trusted_signers"], in["trusted_signers"]) != true { 348 t.Fatalf("Expected out[trusted_signers] to be %v, got %v", in["trusted_signers"], out["trusted_signers"]) 349 } 350 if out["max_ttl"] != int(365000000) { 351 t.Fatalf("Expected out[max_ttl] to be 365000000 (int), got %v", out["max_ttl"]) 352 } 353 if out["smooth_streaming"] != false { 354 t.Fatalf("Expected out[smooth_streaming] to be false, got %v", out["smooth_streaming"]) 355 } 356 if out["default_ttl"] != int(86400) { 357 t.Fatalf("Expected out[default_ttl] to be 86400 (int), got %v", out["default_ttl"]) 358 } 359 if reflect.DeepEqual(out["allowed_methods"], in["allowed_methods"]) != true { 360 t.Fatalf("Expected out[allowed_methods] to be %v, got %v", in["allowed_methods"], out["allowed_methods"]) 361 } 362 if reflect.DeepEqual(out["cached_methods"], in["cached_methods"]) != true { 363 t.Fatalf("Expected out[cached_methods] to be %v, got %v", in["cached_methods"], out["cached_methods"]) 364 } 365 if out["path_pattern"] != "/path1" { 366 t.Fatalf("Expected out[path_pattern] to be /path1, got %v", out["path_pattern"]) 367 } 368 } 369 370 func TestCloudFrontStructure_expandCacheBehaviors(t *testing.T) { 371 data := cacheBehaviorsConf() 372 cbs := expandCacheBehaviors(data) 373 if *cbs.Quantity != 2 { 374 t.Fatalf("Expected Quantity to be 2, got %v", *cbs.Quantity) 375 } 376 if *cbs.Items[0].TargetOriginId != "myS3Origin" { 377 t.Fatalf("Expected first Item's TargetOriginId to be myS3Origin, got %v", *cbs.Items[0].TargetOriginId) 378 } 379 } 380 381 func TestCloudFrontStructure_flattenCacheBehaviors(t *testing.T) { 382 in := cacheBehaviorsConf() 383 cbs := expandCacheBehaviors(in) 384 out := flattenCacheBehaviors(cbs) 385 diff := in.Difference(out) 386 387 if len(diff.List()) > 0 { 388 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 389 } 390 } 391 392 func TestCloudFrontStructure_expandTrustedSigners(t *testing.T) { 393 data := trustedSignersConf() 394 ts := expandTrustedSigners(data) 395 if *ts.Quantity != 2 { 396 t.Fatalf("Expected Quantity to be 2, got %v", *ts.Quantity) 397 } 398 if *ts.Enabled != true { 399 t.Fatalf("Expected Enabled to be true, got %v", *ts.Enabled) 400 } 401 if reflect.DeepEqual(ts.Items, expandStringList(data)) != true { 402 t.Fatalf("Expected Items to be %v, got %v", data, ts.Items) 403 } 404 } 405 406 func TestCloudFrontStructure_flattenTrustedSigners(t *testing.T) { 407 in := trustedSignersConf() 408 ts := expandTrustedSigners(in) 409 out := flattenTrustedSigners(ts) 410 411 if reflect.DeepEqual(in, out) != true { 412 t.Fatalf("Expected out to be %v, got %v", in, out) 413 } 414 } 415 416 func TestCloudFrontStructure_expandTrustedSigners_empty(t *testing.T) { 417 data := []interface{}{} 418 ts := expandTrustedSigners(data) 419 if *ts.Quantity != 0 { 420 t.Fatalf("Expected Quantity to be 0, got %v", *ts.Quantity) 421 } 422 if *ts.Enabled != false { 423 t.Fatalf("Expected Enabled to be true, got %v", *ts.Enabled) 424 } 425 if ts.Items != nil { 426 t.Fatalf("Expected Items to be nil, got %v", ts.Items) 427 } 428 } 429 430 func TestCloudFrontStructure_expandForwardedValues(t *testing.T) { 431 data := forwardedValuesConf() 432 fv := expandForwardedValues(data) 433 if *fv.QueryString != true { 434 t.Fatalf("Expected QueryString to be true, got %v", *fv.QueryString) 435 } 436 if reflect.DeepEqual(fv.Cookies.WhitelistedNames.Items, expandStringList(cookieNamesConf())) != true { 437 t.Fatalf("Expected Cookies.WhitelistedNames.Items to be %v, got %v", cookieNamesConf(), fv.Cookies.WhitelistedNames.Items) 438 } 439 if reflect.DeepEqual(fv.Headers.Items, expandStringList(headersConf())) != true { 440 t.Fatalf("Expected Headers.Items to be %v, got %v", headersConf(), fv.Headers.Items) 441 } 442 } 443 444 func TestCloudFrontStructure_flattenForwardedValues(t *testing.T) { 445 in := forwardedValuesConf() 446 fv := expandForwardedValues(in) 447 out := flattenForwardedValues(fv) 448 449 if out["query_string"] != true { 450 t.Fatalf("Expected out[query_string] to be true, got %v", out["query_string"]) 451 } 452 if out["cookies"].(*schema.Set).Equal(in["cookies"].(*schema.Set)) != true { 453 t.Fatalf("Expected out[cookies] to be %v, got %v", in["cookies"], out["cookies"]) 454 } 455 if reflect.DeepEqual(out["headers"], in["headers"]) != true { 456 t.Fatalf("Expected out[headers] to be %v, got %v", in["headers"], out["headers"]) 457 } 458 } 459 460 func TestCloudFrontStructure_expandHeaders(t *testing.T) { 461 data := headersConf() 462 h := expandHeaders(data) 463 if *h.Quantity != 2 { 464 t.Fatalf("Expected Quantity to be 2, got %v", *h.Quantity) 465 } 466 if reflect.DeepEqual(h.Items, expandStringList(data)) != true { 467 t.Fatalf("Expected Items to be %v, got %v", data, h.Items) 468 } 469 } 470 471 func TestCloudFrontStructure_flattenHeaders(t *testing.T) { 472 in := headersConf() 473 h := expandHeaders(in) 474 out := flattenHeaders(h) 475 476 if reflect.DeepEqual(in, out) != true { 477 t.Fatalf("Expected out to be %v, got %v", in, out) 478 } 479 } 480 481 func TestCloudFrontStructure_expandQueryStringCacheKeys(t *testing.T) { 482 data := queryStringCacheKeysConf() 483 k := expandQueryStringCacheKeys(data) 484 if *k.Quantity != 2 { 485 t.Fatalf("Expected Quantity to be 2, got %v", *k.Quantity) 486 } 487 if reflect.DeepEqual(k.Items, expandStringList(data)) != true { 488 t.Fatalf("Expected Items to be %v, got %v", data, k.Items) 489 } 490 } 491 492 func TestCloudFrontStructure_flattenQueryStringCacheKeys(t *testing.T) { 493 in := queryStringCacheKeysConf() 494 k := expandQueryStringCacheKeys(in) 495 out := flattenQueryStringCacheKeys(k) 496 497 if reflect.DeepEqual(in, out) != true { 498 t.Fatalf("Expected out to be %v, got %v", in, out) 499 } 500 } 501 502 func TestCloudFrontStructure_expandCookiePreference(t *testing.T) { 503 data := cookiePreferenceConf() 504 cp := expandCookiePreference(data) 505 if *cp.Forward != "whitelist" { 506 t.Fatalf("Expected Forward to be whitelist, got %v", *cp.Forward) 507 } 508 if reflect.DeepEqual(cp.WhitelistedNames.Items, expandStringList(cookieNamesConf())) != true { 509 t.Fatalf("Expected WhitelistedNames.Items to be %v, got %v", cookieNamesConf(), cp.WhitelistedNames.Items) 510 } 511 } 512 513 func TestCloudFrontStructure_flattenCookiePreference(t *testing.T) { 514 in := cookiePreferenceConf() 515 cp := expandCookiePreference(in) 516 out := flattenCookiePreference(cp) 517 518 if reflect.DeepEqual(in, out) != true { 519 t.Fatalf("Expected out to be %v, got %v", in, out) 520 } 521 } 522 523 func TestCloudFrontStructure_expandCookieNames(t *testing.T) { 524 data := cookieNamesConf() 525 cn := expandCookieNames(data) 526 if *cn.Quantity != 2 { 527 t.Fatalf("Expected Quantity to be 2, got %v", *cn.Quantity) 528 } 529 if reflect.DeepEqual(cn.Items, expandStringList(data)) != true { 530 t.Fatalf("Expected Items to be %v, got %v", data, cn.Items) 531 } 532 } 533 534 func TestCloudFrontStructure_flattenCookieNames(t *testing.T) { 535 in := cookieNamesConf() 536 cn := expandCookieNames(in) 537 out := flattenCookieNames(cn) 538 539 if reflect.DeepEqual(in, out) != true { 540 t.Fatalf("Expected out to be %v, got %v", in, out) 541 } 542 } 543 544 func TestCloudFrontStructure_expandAllowedMethods(t *testing.T) { 545 data := allowedMethodsConf() 546 am := expandAllowedMethods(data) 547 if *am.Quantity != 7 { 548 t.Fatalf("Expected Quantity to be 7, got %v", *am.Quantity) 549 } 550 if reflect.DeepEqual(am.Items, expandStringList(data)) != true { 551 t.Fatalf("Expected Items to be %v, got %v", data, am.Items) 552 } 553 } 554 555 func TestCloudFrontStructure_flattenAllowedMethods(t *testing.T) { 556 in := allowedMethodsConf() 557 am := expandAllowedMethods(in) 558 out := flattenAllowedMethods(am) 559 560 if reflect.DeepEqual(in, out) != true { 561 t.Fatalf("Expected out to be %v, got %v", in, out) 562 } 563 } 564 565 func TestCloudFrontStructure_expandCachedMethods(t *testing.T) { 566 data := cachedMethodsConf() 567 cm := expandCachedMethods(data) 568 if *cm.Quantity != 3 { 569 t.Fatalf("Expected Quantity to be 3, got %v", *cm.Quantity) 570 } 571 if reflect.DeepEqual(cm.Items, expandStringList(data)) != true { 572 t.Fatalf("Expected Items to be %v, got %v", data, cm.Items) 573 } 574 } 575 576 func TestCloudFrontStructure_flattenCachedMethods(t *testing.T) { 577 in := cachedMethodsConf() 578 cm := expandCachedMethods(in) 579 out := flattenCachedMethods(cm) 580 581 if reflect.DeepEqual(in, out) != true { 582 t.Fatalf("Expected out to be %v, got %v", in, out) 583 } 584 } 585 586 func TestCloudFrontStructure_expandOrigins(t *testing.T) { 587 data := multiOriginConf() 588 origins := expandOrigins(data) 589 if *origins.Quantity != 2 { 590 t.Fatalf("Expected Quantity to be 2, got %v", *origins.Quantity) 591 } 592 if *origins.Items[0].OriginPath != "/" { 593 t.Fatalf("Expected first Item's OriginPath to be /, got %v", *origins.Items[0].OriginPath) 594 } 595 } 596 597 func TestCloudFrontStructure_flattenOrigins(t *testing.T) { 598 in := multiOriginConf() 599 origins := expandOrigins(in) 600 out := flattenOrigins(origins) 601 diff := in.Difference(out) 602 603 if len(diff.List()) > 0 { 604 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 605 } 606 } 607 608 func TestCloudFrontStructure_expandOrigin(t *testing.T) { 609 data := originWithCustomConf() 610 or := expandOrigin(data) 611 if *or.Id != "CustomOrigin" { 612 t.Fatalf("Expected Id to be CustomOrigin, got %v", *or.Id) 613 } 614 if *or.DomainName != "www.example.com" { 615 t.Fatalf("Expected DomainName to be www.example.com, got %v", *or.DomainName) 616 } 617 if *or.OriginPath != "/" { 618 t.Fatalf("Expected OriginPath to be /, got %v", *or.OriginPath) 619 } 620 if *or.CustomOriginConfig.OriginProtocolPolicy != "http-only" { 621 t.Fatalf("Expected CustomOriginConfig.OriginProtocolPolicy to be http-only, got %v", *or.CustomOriginConfig.OriginProtocolPolicy) 622 } 623 if *or.CustomHeaders.Items[0].HeaderValue != "samplevalue" { 624 t.Fatalf("Expected CustomHeaders.Items[0].HeaderValue to be samplevalue, got %v", *or.CustomHeaders.Items[0].HeaderValue) 625 } 626 } 627 628 func TestCloudFrontStructure_flattenOrigin(t *testing.T) { 629 in := originWithCustomConf() 630 or := expandOrigin(in) 631 out := flattenOrigin(or) 632 633 if out["origin_id"] != "CustomOrigin" { 634 t.Fatalf("Expected out[origin_id] to be CustomOrigin, got %v", out["origin_id"]) 635 } 636 if out["domain_name"] != "www.example.com" { 637 t.Fatalf("Expected out[domain_name] to be www.example.com, got %v", out["domain_name"]) 638 } 639 if out["origin_path"] != "/" { 640 t.Fatalf("Expected out[origin_path] to be /, got %v", out["origin_path"]) 641 } 642 if out["custom_origin_config"].(*schema.Set).Equal(in["custom_origin_config"].(*schema.Set)) != true { 643 t.Fatalf("Expected out[custom_origin_config] to be %v, got %v", in["custom_origin_config"], out["custom_origin_config"]) 644 } 645 } 646 647 func TestCloudFrontStructure_expandCustomHeaders(t *testing.T) { 648 in := originCustomHeadersConf() 649 chs := expandCustomHeaders(in) 650 if *chs.Quantity != 2 { 651 t.Fatalf("Expected Quantity to be 2, got %v", *chs.Quantity) 652 } 653 if *chs.Items[0].HeaderValue != "samplevalue" { 654 t.Fatalf("Expected first Item's HeaderValue to be samplevalue, got %v", *chs.Items[0].HeaderValue) 655 } 656 } 657 658 func TestCloudFrontStructure_flattenCustomHeaders(t *testing.T) { 659 in := originCustomHeadersConf() 660 chs := expandCustomHeaders(in) 661 out := flattenCustomHeaders(chs) 662 diff := in.Difference(out) 663 664 if len(diff.List()) > 0 { 665 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 666 } 667 } 668 669 func TestCloudFrontStructure_flattenOriginCustomHeader(t *testing.T) { 670 in := originCustomHeaderConf1() 671 och := expandOriginCustomHeader(in) 672 out := flattenOriginCustomHeader(och) 673 674 if out["name"] != "X-Custom-Header1" { 675 t.Fatalf("Expected out[name] to be X-Custom-Header1, got %v", out["name"]) 676 } 677 if out["value"] != "samplevalue" { 678 t.Fatalf("Expected out[value] to be samplevalue, got %v", out["value"]) 679 } 680 } 681 682 func TestCloudFrontStructure_expandOriginCustomHeader(t *testing.T) { 683 in := originCustomHeaderConf1() 684 och := expandOriginCustomHeader(in) 685 686 if *och.HeaderName != "X-Custom-Header1" { 687 t.Fatalf("Expected HeaderName to be X-Custom-Header1, got %v", *och.HeaderName) 688 } 689 if *och.HeaderValue != "samplevalue" { 690 t.Fatalf("Expected HeaderValue to be samplevalue, got %v", *och.HeaderValue) 691 } 692 } 693 694 func TestCloudFrontStructure_expandCustomOriginConfig(t *testing.T) { 695 data := customOriginConf() 696 co := expandCustomOriginConfig(data) 697 if *co.OriginProtocolPolicy != "http-only" { 698 t.Fatalf("Expected OriginProtocolPolicy to be http-only, got %v", *co.OriginProtocolPolicy) 699 } 700 if *co.HTTPPort != 80 { 701 t.Fatalf("Expected HTTPPort to be 80, got %v", *co.HTTPPort) 702 } 703 if *co.HTTPSPort != 443 { 704 t.Fatalf("Expected HTTPSPort to be 443, got %v", *co.HTTPSPort) 705 } 706 } 707 708 func TestCloudFrontStructure_flattenCustomOriginConfig(t *testing.T) { 709 in := customOriginConf() 710 co := expandCustomOriginConfig(in) 711 out := flattenCustomOriginConfig(co) 712 713 if reflect.DeepEqual(in, out) != true { 714 t.Fatalf("Expected out to be %v, got %v", in, out) 715 } 716 } 717 718 func TestCloudFrontStructure_expandCustomOriginConfigSSL(t *testing.T) { 719 in := customOriginSslProtocolsConf() 720 ocs := expandCustomOriginConfigSSL(in) 721 if *ocs.Quantity != 4 { 722 t.Fatalf("Expected Quantity to be 4, got %v", *ocs.Quantity) 723 } 724 if *ocs.Items[0] != "SSLv3" { 725 t.Fatalf("Expected first Item to be SSLv3, got %v", *ocs.Items[0]) 726 } 727 } 728 729 func TestCloudFrontStructure_flattenCustomOriginConfigSSL(t *testing.T) { 730 in := customOriginSslProtocolsConf() 731 ocs := expandCustomOriginConfigSSL(in) 732 out := flattenCustomOriginConfigSSL(ocs) 733 734 if reflect.DeepEqual(in, out) != true { 735 t.Fatalf("Expected out to be %v, got %v", in, out) 736 } 737 } 738 739 func TestCloudFrontStructure_expandS3OriginConfig(t *testing.T) { 740 data := s3OriginConf() 741 s3o := expandS3OriginConfig(data) 742 if *s3o.OriginAccessIdentity != "origin-access-identity/cloudfront/E127EXAMPLE51Z" { 743 t.Fatalf("Expected OriginAccessIdentity to be origin-access-identity/cloudfront/E127EXAMPLE51Z, got %v", *s3o.OriginAccessIdentity) 744 } 745 } 746 747 func TestCloudFrontStructure_flattenS3OriginConfig(t *testing.T) { 748 in := s3OriginConf() 749 s3o := expandS3OriginConfig(in) 750 out := flattenS3OriginConfig(s3o) 751 752 if reflect.DeepEqual(in, out) != true { 753 t.Fatalf("Expected out to be %v, got %v", in, out) 754 } 755 } 756 757 func TestCloudFrontStructure_expandCustomErrorResponses(t *testing.T) { 758 data := customErrorResponsesConfSet() 759 ers := expandCustomErrorResponses(data) 760 if *ers.Quantity != 2 { 761 t.Fatalf("Expected Quantity to be 2, got %v", *ers.Quantity) 762 } 763 if *ers.Items[0].ResponsePagePath != "/error-pages/404.html" { 764 t.Fatalf("Expected ResponsePagePath in first Item to be /error-pages/404.html, got %v", *ers.Items[0].ResponsePagePath) 765 } 766 } 767 768 func TestCloudFrontStructure_flattenCustomErrorResponses(t *testing.T) { 769 in := customErrorResponsesConfSet() 770 ers := expandCustomErrorResponses(in) 771 out := flattenCustomErrorResponses(ers) 772 773 if in.Equal(out) != true { 774 t.Fatalf("Expected out to be %v, got %v", in, out) 775 } 776 } 777 778 func TestCloudFrontStructure_expandCustomErrorResponse(t *testing.T) { 779 data := customErrorResponsesConfFirst() 780 er := expandCustomErrorResponse(data) 781 if *er.ErrorCode != 404 { 782 t.Fatalf("Expected ErrorCode to be 404, got %v", *er.ErrorCode) 783 } 784 if *er.ErrorCachingMinTTL != 30 { 785 t.Fatalf("Expected ErrorCachingMinTTL to be 30, got %v", *er.ErrorCachingMinTTL) 786 } 787 if *er.ResponseCode != "200" { 788 t.Fatalf("Expected ResponseCode to be 200 (as string), got %v", *er.ResponseCode) 789 } 790 if *er.ResponsePagePath != "/error-pages/404.html" { 791 t.Fatalf("Expected ResponsePagePath to be /error-pages/404.html, got %v", *er.ResponsePagePath) 792 } 793 } 794 795 func TestCloudFrontStructure_expandCustomErrorResponse_emptyResponseCode(t *testing.T) { 796 data := customErrorResponseConfNoResponseCode() 797 er := expandCustomErrorResponse(data) 798 if *er.ResponseCode != "" { 799 t.Fatalf("Expected ResponseCode to be empty string, got %v", *er.ResponseCode) 800 } 801 if *er.ResponsePagePath != "" { 802 t.Fatalf("Expected ResponsePagePath to be empty string, got %v", *er.ResponsePagePath) 803 } 804 } 805 806 func TestCloudFrontStructure_flattenCustomErrorResponse(t *testing.T) { 807 in := customErrorResponsesConfFirst() 808 er := expandCustomErrorResponse(in) 809 out := flattenCustomErrorResponse(er) 810 811 if reflect.DeepEqual(in, out) != true { 812 t.Fatalf("Expected out to be %v, got %v", in, out) 813 } 814 } 815 816 func TestCloudFrontStructure_expandLoggingConfig(t *testing.T) { 817 data := loggingConfigConf() 818 819 lc := expandLoggingConfig(data) 820 if *lc.Enabled != true { 821 t.Fatalf("Expected Enabled to be true, got %v", *lc.Enabled) 822 } 823 if *lc.Prefix != "myprefix" { 824 t.Fatalf("Expected Prefix to be myprefix, got %v", *lc.Prefix) 825 } 826 if *lc.Bucket != "mylogs.s3.amazonaws.com" { 827 t.Fatalf("Expected Bucket to be mylogs.s3.amazonaws.com, got %v", *lc.Bucket) 828 } 829 if *lc.IncludeCookies != false { 830 t.Fatalf("Expected IncludeCookies to be false, got %v", *lc.IncludeCookies) 831 } 832 } 833 834 func TestCloudFrontStructure_expandLoggingConfig_nilValue(t *testing.T) { 835 lc := expandLoggingConfig(nil) 836 if *lc.Enabled != false { 837 t.Fatalf("Expected Enabled to be false, got %v", *lc.Enabled) 838 } 839 if *lc.Prefix != "" { 840 t.Fatalf("Expected Prefix to be blank, got %v", *lc.Prefix) 841 } 842 if *lc.Bucket != "" { 843 t.Fatalf("Expected Bucket to be blank, got %v", *lc.Bucket) 844 } 845 if *lc.IncludeCookies != false { 846 t.Fatalf("Expected IncludeCookies to be false, got %v", *lc.IncludeCookies) 847 } 848 } 849 850 func TestCloudFrontStructure_flattenLoggingConfig(t *testing.T) { 851 in := loggingConfigConf() 852 lc := expandLoggingConfig(in) 853 out := flattenLoggingConfig(lc) 854 diff := schema.NewSet(loggingConfigHash, []interface{}{in}).Difference(out) 855 856 if len(diff.List()) > 0 { 857 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 858 } 859 } 860 861 func TestCloudFrontStructure_expandAliases(t *testing.T) { 862 data := aliasesConf() 863 a := expandAliases(data) 864 if *a.Quantity != 2 { 865 t.Fatalf("Expected Quantity to be 2, got %v", *a.Quantity) 866 } 867 if reflect.DeepEqual(a.Items, expandStringList(data.List())) != true { 868 t.Fatalf("Expected Items to be [example.com www.example.com], got %v", a.Items) 869 } 870 } 871 872 func TestCloudFrontStructure_flattenAliases(t *testing.T) { 873 in := aliasesConf() 874 a := expandAliases(in) 875 out := flattenAliases(a) 876 diff := in.Difference(out) 877 878 if len(diff.List()) > 0 { 879 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 880 } 881 } 882 883 func TestCloudFrontStructure_expandRestrictions(t *testing.T) { 884 data := geoRestrictionsConf() 885 r := expandRestrictions(data) 886 if *r.GeoRestriction.RestrictionType != "whitelist" { 887 t.Fatalf("Expected GeoRestriction.RestrictionType to be whitelist, got %v", *r.GeoRestriction.RestrictionType) 888 } 889 } 890 891 func TestCloudFrontStructure_flattenRestrictions(t *testing.T) { 892 in := geoRestrictionsConf() 893 r := expandRestrictions(in) 894 out := flattenRestrictions(r) 895 diff := schema.NewSet(restrictionsHash, []interface{}{in}).Difference(out) 896 897 if len(diff.List()) > 0 { 898 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 899 } 900 } 901 902 func TestCloudFrontStructure_expandGeoRestriction_whitelist(t *testing.T) { 903 data := geoRestrictionWhitelistConf() 904 gr := expandGeoRestriction(data) 905 if *gr.RestrictionType != "whitelist" { 906 t.Fatalf("Expected RestrictionType to be whitelist, got %v", *gr.RestrictionType) 907 } 908 if *gr.Quantity != 3 { 909 t.Fatalf("Expected Quantity to be 3, got %v", *gr.Quantity) 910 } 911 if reflect.DeepEqual(gr.Items, aws.StringSlice([]string{"CA", "GB", "US"})) != true { 912 t.Fatalf("Expected Items be [CA, GB, US], got %v", gr.Items) 913 } 914 } 915 916 func TestCloudFrontStructure_flattenGeoRestriction_whitelist(t *testing.T) { 917 in := geoRestrictionWhitelistConf() 918 gr := expandGeoRestriction(in) 919 out := flattenGeoRestriction(gr) 920 921 if reflect.DeepEqual(in, out) != true { 922 t.Fatalf("Expected out to be %v, got %v", in, out) 923 } 924 } 925 926 func TestCloudFrontStructure_expandGeoRestriction_no_items(t *testing.T) { 927 data := geoRestrictionConfNoItems() 928 gr := expandGeoRestriction(data) 929 if *gr.RestrictionType != "none" { 930 t.Fatalf("Expected RestrictionType to be none, got %v", *gr.RestrictionType) 931 } 932 if *gr.Quantity != 0 { 933 t.Fatalf("Expected Quantity to be 0, got %v", *gr.Quantity) 934 } 935 if gr.Items != nil { 936 t.Fatalf("Expected Items to not be set, got %v", gr.Items) 937 } 938 } 939 940 func TestCloudFrontStructure_flattenGeoRestriction_no_items(t *testing.T) { 941 in := geoRestrictionConfNoItems() 942 gr := expandGeoRestriction(in) 943 out := flattenGeoRestriction(gr) 944 945 if reflect.DeepEqual(in, out) != true { 946 t.Fatalf("Expected out to be %v, got %v", in, out) 947 } 948 } 949 950 func TestCloudFrontStructure_expandViewerCertificate_cloudfront_default_certificate(t *testing.T) { 951 data := viewerCertificateConfSetCloudFrontDefault() 952 vc := expandViewerCertificate(data) 953 if vc.ACMCertificateArn != nil { 954 t.Fatalf("Expected ACMCertificateArn to be unset, got %v", *vc.ACMCertificateArn) 955 } 956 if *vc.CloudFrontDefaultCertificate != true { 957 t.Fatalf("Expected CloudFrontDefaultCertificate to be true, got %v", *vc.CloudFrontDefaultCertificate) 958 } 959 if vc.IAMCertificateId != nil { 960 t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.IAMCertificateId) 961 } 962 if vc.SSLSupportMethod != nil { 963 t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.SSLSupportMethod) 964 } 965 if vc.MinimumProtocolVersion != nil { 966 t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.MinimumProtocolVersion) 967 } 968 } 969 970 func TestCloudFrontStructure_flattenViewerCertificate_cloudfront_default_certificate(t *testing.T) { 971 in := viewerCertificateConfSetCloudFrontDefault() 972 vc := expandViewerCertificate(in) 973 out := flattenViewerCertificate(vc) 974 diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out) 975 976 if len(diff.List()) > 0 { 977 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 978 } 979 } 980 981 func TestCloudFrontStructure_expandViewerCertificate_iam_certificate_id(t *testing.T) { 982 data := viewerCertificateConfSetIAM() 983 vc := expandViewerCertificate(data) 984 if vc.ACMCertificateArn != nil { 985 t.Fatalf("Expected ACMCertificateArn to be unset, got %v", *vc.ACMCertificateArn) 986 } 987 if vc.CloudFrontDefaultCertificate != nil { 988 t.Fatalf("Expected CloudFrontDefaultCertificate to be unset, got %v", *vc.CloudFrontDefaultCertificate) 989 } 990 if *vc.IAMCertificateId != "iamcert-01234567" { 991 t.Fatalf("Expected IAMCertificateId to be iamcert-01234567, got %v", *vc.IAMCertificateId) 992 } 993 if *vc.SSLSupportMethod != "vip" { 994 t.Fatalf("Expected IAMCertificateId to be vip, got %v", *vc.SSLSupportMethod) 995 } 996 if *vc.MinimumProtocolVersion != "TLSv1" { 997 t.Fatalf("Expected IAMCertificateId to be TLSv1, got %v", *vc.MinimumProtocolVersion) 998 } 999 } 1000 1001 func TestCloudFrontStructure_expandViewerCertificate_acm_certificate_arn(t *testing.T) { 1002 data := viewerCertificateConfSetACM() 1003 vc := expandViewerCertificate(data) 1004 if *vc.ACMCertificateArn != "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" { 1005 t.Fatalf("Expected ACMCertificateArn to be arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012, got %v", *vc.ACMCertificateArn) 1006 } 1007 if vc.CloudFrontDefaultCertificate != nil { 1008 t.Fatalf("Expected CloudFrontDefaultCertificate to be unset, got %v", *vc.CloudFrontDefaultCertificate) 1009 } 1010 if vc.IAMCertificateId != nil { 1011 t.Fatalf("Expected IAMCertificateId to be unset, got %v", *vc.IAMCertificateId) 1012 } 1013 if *vc.SSLSupportMethod != "sni-only" { 1014 t.Fatalf("Expected IAMCertificateId to be sni-only, got %v", *vc.SSLSupportMethod) 1015 } 1016 if *vc.MinimumProtocolVersion != "TLSv1" { 1017 t.Fatalf("Expected IAMCertificateId to be TLSv1, got %v", *vc.MinimumProtocolVersion) 1018 } 1019 } 1020 1021 func TestCloudFrontStructure_falttenViewerCertificate_iam_certificate_id(t *testing.T) { 1022 in := viewerCertificateConfSetIAM() 1023 vc := expandViewerCertificate(in) 1024 out := flattenViewerCertificate(vc) 1025 diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out) 1026 1027 if len(diff.List()) > 0 { 1028 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 1029 } 1030 } 1031 1032 func TestCloudFrontStructure_falttenViewerCertificate_acm_certificate_arn(t *testing.T) { 1033 in := viewerCertificateConfSetACM() 1034 vc := expandViewerCertificate(in) 1035 out := flattenViewerCertificate(vc) 1036 diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out) 1037 1038 if len(diff.List()) > 0 { 1039 t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff) 1040 } 1041 } 1042 1043 func TestCloudFrontStructure_viewerCertificateHash_IAM(t *testing.T) { 1044 in := viewerCertificateConfSetIAM() 1045 out := viewerCertificateHash(in) 1046 expected := 1157261784 1047 1048 if expected != out { 1049 t.Fatalf("Expected %v, got %v", expected, out) 1050 } 1051 } 1052 1053 func TestCloudFrontStructure_viewerCertificateHash_ACM(t *testing.T) { 1054 in := viewerCertificateConfSetACM() 1055 out := viewerCertificateHash(in) 1056 expected := 2883600425 1057 1058 if expected != out { 1059 t.Fatalf("Expected %v, got %v", expected, out) 1060 } 1061 } 1062 1063 func TestCloudFrontStructure_viewerCertificateHash_default(t *testing.T) { 1064 in := viewerCertificateConfSetCloudFrontDefault() 1065 out := viewerCertificateHash(in) 1066 expected := 69840937 1067 1068 if expected != out { 1069 t.Fatalf("Expected %v, got %v", expected, out) 1070 } 1071 }