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