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