github.com/cbroglie/terraform@v0.7.0-rc3.0.20170410193827-735dfc416d46/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  	var outSet, ok = out["lambda_function_association"].(*schema.Set)
   368  	if !ok {
   369  		t.Fatalf("out['lambda_function_association'] is not a slice as expected: %#v", out["lambda_function_association"])
   370  	}
   371  
   372  	inSet, ok := in["lambda_function_association"].(*schema.Set)
   373  	if !ok {
   374  		t.Fatalf("in['lambda_function_association'] is not a set as expected: %#v", in["lambda_function_association"])
   375  	}
   376  
   377  	if !inSet.Equal(outSet) {
   378  		t.Fatalf("in / out sets are not equal, in: \n%#v\n\nout: \n%#v\n", inSet, outSet)
   379  	}
   380  
   381  	diff = out["forwarded_values"].(*schema.Set).Difference(in["forwarded_values"].(*schema.Set))
   382  	if len(diff.List()) > 0 {
   383  		t.Fatalf("Expected out[forwarded_values] to be %v, got %v, diff: %v", out["forwarded_values"], in["forwarded_values"], diff)
   384  	}
   385  	if out["min_ttl"] != int(86400) {
   386  		t.Fatalf("Expected out[min_ttl] to be 86400 (int), got %v", out["forwarded_values"])
   387  	}
   388  	if reflect.DeepEqual(out["trusted_signers"], in["trusted_signers"]) != true {
   389  		t.Fatalf("Expected out[trusted_signers] to be %v, got %v", in["trusted_signers"], out["trusted_signers"])
   390  	}
   391  	if out["max_ttl"] != int(365000000) {
   392  		t.Fatalf("Expected out[max_ttl] to be 365000000 (int), got %v", out["max_ttl"])
   393  	}
   394  	if out["smooth_streaming"] != false {
   395  		t.Fatalf("Expected out[smooth_streaming] to be false, got %v", out["smooth_streaming"])
   396  	}
   397  	if out["default_ttl"] != int(86400) {
   398  		t.Fatalf("Expected out[default_ttl] to be 86400 (int), got %v", out["default_ttl"])
   399  	}
   400  	if reflect.DeepEqual(out["allowed_methods"], in["allowed_methods"]) != true {
   401  		t.Fatalf("Expected out[allowed_methods] to be %v, got %v", in["allowed_methods"], out["allowed_methods"])
   402  	}
   403  	if reflect.DeepEqual(out["cached_methods"], in["cached_methods"]) != true {
   404  		t.Fatalf("Expected out[cached_methods] to be %v, got %v", in["cached_methods"], out["cached_methods"])
   405  	}
   406  	if out["path_pattern"] != "/path1" {
   407  		t.Fatalf("Expected out[path_pattern] to be /path1, got %v", out["path_pattern"])
   408  	}
   409  }
   410  
   411  func TestCloudFrontStructure_expandCacheBehaviors(t *testing.T) {
   412  	data := cacheBehaviorsConf()
   413  	cbs := expandCacheBehaviors(data)
   414  	if *cbs.Quantity != 2 {
   415  		t.Fatalf("Expected Quantity to be 2, got %v", *cbs.Quantity)
   416  	}
   417  	if *cbs.Items[0].TargetOriginId != "myS3Origin" {
   418  		t.Fatalf("Expected first Item's TargetOriginId to be 	myS3Origin, got %v", *cbs.Items[0].TargetOriginId)
   419  	}
   420  }
   421  
   422  func TestCloudFrontStructure_flattenCacheBehaviors(t *testing.T) {
   423  	in := cacheBehaviorsConf()
   424  	cbs := expandCacheBehaviors(in)
   425  	out := flattenCacheBehaviors(cbs)
   426  	diff := in.Difference(out)
   427  
   428  	if len(diff.List()) > 0 {
   429  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   430  	}
   431  }
   432  
   433  func TestCloudFrontStructure_expandTrustedSigners(t *testing.T) {
   434  	data := trustedSignersConf()
   435  	ts := expandTrustedSigners(data)
   436  	if *ts.Quantity != 2 {
   437  		t.Fatalf("Expected Quantity to be 2, got %v", *ts.Quantity)
   438  	}
   439  	if *ts.Enabled != true {
   440  		t.Fatalf("Expected Enabled to be true, got %v", *ts.Enabled)
   441  	}
   442  	if reflect.DeepEqual(ts.Items, expandStringList(data)) != true {
   443  		t.Fatalf("Expected Items to be %v, got %v", data, ts.Items)
   444  	}
   445  }
   446  
   447  func TestCloudFrontStructure_flattenTrustedSigners(t *testing.T) {
   448  	in := trustedSignersConf()
   449  	ts := expandTrustedSigners(in)
   450  	out := flattenTrustedSigners(ts)
   451  
   452  	if reflect.DeepEqual(in, out) != true {
   453  		t.Fatalf("Expected out to be %v, got %v", in, out)
   454  	}
   455  }
   456  
   457  func TestCloudFrontStructure_expandTrustedSigners_empty(t *testing.T) {
   458  	data := []interface{}{}
   459  	ts := expandTrustedSigners(data)
   460  	if *ts.Quantity != 0 {
   461  		t.Fatalf("Expected Quantity to be 0, got %v", *ts.Quantity)
   462  	}
   463  	if *ts.Enabled != false {
   464  		t.Fatalf("Expected Enabled to be true, got %v", *ts.Enabled)
   465  	}
   466  	if ts.Items != nil {
   467  		t.Fatalf("Expected Items to be nil, got %v", ts.Items)
   468  	}
   469  }
   470  
   471  func TestCloudFrontStructure_expandLambdaFunctionAssociations(t *testing.T) {
   472  	data := lambdaFunctionAssociationsConf()
   473  	lfa := expandLambdaFunctionAssociations(data.List())
   474  	if *lfa.Quantity != 2 {
   475  		t.Fatalf("Expected Quantity to be 2, got %v", *lfa.Quantity)
   476  	}
   477  	if len(lfa.Items) != 2 {
   478  		t.Fatalf("Expected Items to be len 2, got %v", len(lfa.Items))
   479  	}
   480  	if et := "viewer-request"; *lfa.Items[0].EventType != et {
   481  		t.Fatalf("Expected first Item's EventType to be %q, got %q", et, *lfa.Items[0].EventType)
   482  	}
   483  	if et := "origin-response"; *lfa.Items[1].EventType != et {
   484  		t.Fatalf("Expected second Item's EventType to be %q, got %q", et, *lfa.Items[1].EventType)
   485  	}
   486  }
   487  
   488  func TestCloudFrontStructure_flattenlambdaFunctionAssociations(t *testing.T) {
   489  	in := lambdaFunctionAssociationsConf()
   490  	lfa := expandLambdaFunctionAssociations(in.List())
   491  	out := flattenLambdaFunctionAssociations(lfa)
   492  
   493  	if reflect.DeepEqual(in.List(), out.List()) != true {
   494  		t.Fatalf("Expected out to be %v, got %v", in, out)
   495  	}
   496  }
   497  
   498  func TestCloudFrontStructure_expandlambdaFunctionAssociations_empty(t *testing.T) {
   499  	data := new(schema.Set)
   500  	lfa := expandLambdaFunctionAssociations(data.List())
   501  	if *lfa.Quantity != 0 {
   502  		t.Fatalf("Expected Quantity to be 0, got %v", *lfa.Quantity)
   503  	}
   504  	if len(lfa.Items) != 0 {
   505  		t.Fatalf("Expected Items to be len 0, got %v", len(lfa.Items))
   506  	}
   507  	if reflect.DeepEqual(lfa.Items, []*cloudfront.LambdaFunctionAssociation{}) != true {
   508  		t.Fatalf("Expected Items to be empty, got %v", lfa.Items)
   509  	}
   510  }
   511  
   512  func TestCloudFrontStructure_expandForwardedValues(t *testing.T) {
   513  	data := forwardedValuesConf()
   514  	fv := expandForwardedValues(data)
   515  	if *fv.QueryString != true {
   516  		t.Fatalf("Expected QueryString to be true, got %v", *fv.QueryString)
   517  	}
   518  	if reflect.DeepEqual(fv.Cookies.WhitelistedNames.Items, expandStringList(cookieNamesConf())) != true {
   519  		t.Fatalf("Expected Cookies.WhitelistedNames.Items to be %v, got %v", cookieNamesConf(), fv.Cookies.WhitelistedNames.Items)
   520  	}
   521  	if reflect.DeepEqual(fv.Headers.Items, expandStringList(headersConf())) != true {
   522  		t.Fatalf("Expected Headers.Items to be %v, got %v", headersConf(), fv.Headers.Items)
   523  	}
   524  }
   525  
   526  func TestCloudFrontStructure_flattenForwardedValues(t *testing.T) {
   527  	in := forwardedValuesConf()
   528  	fv := expandForwardedValues(in)
   529  	out := flattenForwardedValues(fv)
   530  
   531  	if out["query_string"] != true {
   532  		t.Fatalf("Expected out[query_string] to be true, got %v", out["query_string"])
   533  	}
   534  	if out["cookies"].(*schema.Set).Equal(in["cookies"].(*schema.Set)) != true {
   535  		t.Fatalf("Expected out[cookies] to be %v, got %v", in["cookies"], out["cookies"])
   536  	}
   537  	if reflect.DeepEqual(out["headers"], in["headers"]) != true {
   538  		t.Fatalf("Expected out[headers] to be %v, got %v", in["headers"], out["headers"])
   539  	}
   540  }
   541  
   542  func TestCloudFrontStructure_expandHeaders(t *testing.T) {
   543  	data := headersConf()
   544  	h := expandHeaders(data)
   545  	if *h.Quantity != 2 {
   546  		t.Fatalf("Expected Quantity to be 2, got %v", *h.Quantity)
   547  	}
   548  	if reflect.DeepEqual(h.Items, expandStringList(data)) != true {
   549  		t.Fatalf("Expected Items to be %v, got %v", data, h.Items)
   550  	}
   551  }
   552  
   553  func TestCloudFrontStructure_flattenHeaders(t *testing.T) {
   554  	in := headersConf()
   555  	h := expandHeaders(in)
   556  	out := flattenHeaders(h)
   557  
   558  	if reflect.DeepEqual(in, out) != true {
   559  		t.Fatalf("Expected out to be %v, got %v", in, out)
   560  	}
   561  }
   562  
   563  func TestCloudFrontStructure_expandQueryStringCacheKeys(t *testing.T) {
   564  	data := queryStringCacheKeysConf()
   565  	k := expandQueryStringCacheKeys(data)
   566  	if *k.Quantity != 2 {
   567  		t.Fatalf("Expected Quantity to be 2, got %v", *k.Quantity)
   568  	}
   569  	if reflect.DeepEqual(k.Items, expandStringList(data)) != true {
   570  		t.Fatalf("Expected Items to be %v, got %v", data, k.Items)
   571  	}
   572  }
   573  
   574  func TestCloudFrontStructure_flattenQueryStringCacheKeys(t *testing.T) {
   575  	in := queryStringCacheKeysConf()
   576  	k := expandQueryStringCacheKeys(in)
   577  	out := flattenQueryStringCacheKeys(k)
   578  
   579  	if reflect.DeepEqual(in, out) != true {
   580  		t.Fatalf("Expected out to be %v, got %v", in, out)
   581  	}
   582  }
   583  
   584  func TestCloudFrontStructure_expandCookiePreference(t *testing.T) {
   585  	data := cookiePreferenceConf()
   586  	cp := expandCookiePreference(data)
   587  	if *cp.Forward != "whitelist" {
   588  		t.Fatalf("Expected Forward to be whitelist, got %v", *cp.Forward)
   589  	}
   590  	if reflect.DeepEqual(cp.WhitelistedNames.Items, expandStringList(cookieNamesConf())) != true {
   591  		t.Fatalf("Expected WhitelistedNames.Items to be %v, got %v", cookieNamesConf(), cp.WhitelistedNames.Items)
   592  	}
   593  }
   594  
   595  func TestCloudFrontStructure_flattenCookiePreference(t *testing.T) {
   596  	in := cookiePreferenceConf()
   597  	cp := expandCookiePreference(in)
   598  	out := flattenCookiePreference(cp)
   599  
   600  	if reflect.DeepEqual(in, out) != true {
   601  		t.Fatalf("Expected out to be %v, got %v", in, out)
   602  	}
   603  }
   604  
   605  func TestCloudFrontStructure_expandCookieNames(t *testing.T) {
   606  	data := cookieNamesConf()
   607  	cn := expandCookieNames(data)
   608  	if *cn.Quantity != 2 {
   609  		t.Fatalf("Expected Quantity to be 2, got %v", *cn.Quantity)
   610  	}
   611  	if reflect.DeepEqual(cn.Items, expandStringList(data)) != true {
   612  		t.Fatalf("Expected Items to be %v, got %v", data, cn.Items)
   613  	}
   614  }
   615  
   616  func TestCloudFrontStructure_flattenCookieNames(t *testing.T) {
   617  	in := cookieNamesConf()
   618  	cn := expandCookieNames(in)
   619  	out := flattenCookieNames(cn)
   620  
   621  	if reflect.DeepEqual(in, out) != true {
   622  		t.Fatalf("Expected out to be %v, got %v", in, out)
   623  	}
   624  }
   625  
   626  func TestCloudFrontStructure_expandAllowedMethods(t *testing.T) {
   627  	data := allowedMethodsConf()
   628  	am := expandAllowedMethods(data)
   629  	if *am.Quantity != 7 {
   630  		t.Fatalf("Expected Quantity to be 7, got %v", *am.Quantity)
   631  	}
   632  	if reflect.DeepEqual(am.Items, expandStringList(data)) != true {
   633  		t.Fatalf("Expected Items to be %v, got %v", data, am.Items)
   634  	}
   635  }
   636  
   637  func TestCloudFrontStructure_flattenAllowedMethods(t *testing.T) {
   638  	in := allowedMethodsConf()
   639  	am := expandAllowedMethods(in)
   640  	out := flattenAllowedMethods(am)
   641  
   642  	if reflect.DeepEqual(in, out) != true {
   643  		t.Fatalf("Expected out to be %v, got %v", in, out)
   644  	}
   645  }
   646  
   647  func TestCloudFrontStructure_expandCachedMethods(t *testing.T) {
   648  	data := cachedMethodsConf()
   649  	cm := expandCachedMethods(data)
   650  	if *cm.Quantity != 3 {
   651  		t.Fatalf("Expected Quantity to be 3, got %v", *cm.Quantity)
   652  	}
   653  	if reflect.DeepEqual(cm.Items, expandStringList(data)) != true {
   654  		t.Fatalf("Expected Items to be %v, got %v", data, cm.Items)
   655  	}
   656  }
   657  
   658  func TestCloudFrontStructure_flattenCachedMethods(t *testing.T) {
   659  	in := cachedMethodsConf()
   660  	cm := expandCachedMethods(in)
   661  	out := flattenCachedMethods(cm)
   662  
   663  	if reflect.DeepEqual(in, out) != true {
   664  		t.Fatalf("Expected out to be %v, got %v", in, out)
   665  	}
   666  }
   667  
   668  func TestCloudFrontStructure_expandOrigins(t *testing.T) {
   669  	data := multiOriginConf()
   670  	origins := expandOrigins(data)
   671  	if *origins.Quantity != 2 {
   672  		t.Fatalf("Expected Quantity to be 2, got %v", *origins.Quantity)
   673  	}
   674  	if *origins.Items[0].OriginPath != "/" {
   675  		t.Fatalf("Expected first Item's OriginPath to be /, got %v", *origins.Items[0].OriginPath)
   676  	}
   677  }
   678  
   679  func TestCloudFrontStructure_flattenOrigins(t *testing.T) {
   680  	in := multiOriginConf()
   681  	origins := expandOrigins(in)
   682  	out := flattenOrigins(origins)
   683  	diff := in.Difference(out)
   684  
   685  	if len(diff.List()) > 0 {
   686  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   687  	}
   688  }
   689  
   690  func TestCloudFrontStructure_expandOrigin(t *testing.T) {
   691  	data := originWithCustomConf()
   692  	or := expandOrigin(data)
   693  	if *or.Id != "CustomOrigin" {
   694  		t.Fatalf("Expected Id to be CustomOrigin, got %v", *or.Id)
   695  	}
   696  	if *or.DomainName != "www.example.com" {
   697  		t.Fatalf("Expected DomainName to be www.example.com, got %v", *or.DomainName)
   698  	}
   699  	if *or.OriginPath != "/" {
   700  		t.Fatalf("Expected OriginPath to be /, got %v", *or.OriginPath)
   701  	}
   702  	if *or.CustomOriginConfig.OriginProtocolPolicy != "http-only" {
   703  		t.Fatalf("Expected CustomOriginConfig.OriginProtocolPolicy to be http-only, got %v", *or.CustomOriginConfig.OriginProtocolPolicy)
   704  	}
   705  	if *or.CustomHeaders.Items[0].HeaderValue != "samplevalue" {
   706  		t.Fatalf("Expected CustomHeaders.Items[0].HeaderValue to be samplevalue, got %v", *or.CustomHeaders.Items[0].HeaderValue)
   707  	}
   708  }
   709  
   710  func TestCloudFrontStructure_flattenOrigin(t *testing.T) {
   711  	in := originWithCustomConf()
   712  	or := expandOrigin(in)
   713  	out := flattenOrigin(or)
   714  
   715  	if out["origin_id"] != "CustomOrigin" {
   716  		t.Fatalf("Expected out[origin_id] to be CustomOrigin, got %v", out["origin_id"])
   717  	}
   718  	if out["domain_name"] != "www.example.com" {
   719  		t.Fatalf("Expected out[domain_name] to be www.example.com, got %v", out["domain_name"])
   720  	}
   721  	if out["origin_path"] != "/" {
   722  		t.Fatalf("Expected out[origin_path] to be /, got %v", out["origin_path"])
   723  	}
   724  	if out["custom_origin_config"].(*schema.Set).Equal(in["custom_origin_config"].(*schema.Set)) != true {
   725  		t.Fatalf("Expected out[custom_origin_config] to be %v, got %v", in["custom_origin_config"], out["custom_origin_config"])
   726  	}
   727  }
   728  
   729  func TestCloudFrontStructure_expandCustomHeaders(t *testing.T) {
   730  	in := originCustomHeadersConf()
   731  	chs := expandCustomHeaders(in)
   732  	if *chs.Quantity != 2 {
   733  		t.Fatalf("Expected Quantity to be 2, got %v", *chs.Quantity)
   734  	}
   735  	if *chs.Items[0].HeaderValue != "samplevalue" {
   736  		t.Fatalf("Expected first Item's HeaderValue to be samplevalue, got %v", *chs.Items[0].HeaderValue)
   737  	}
   738  }
   739  
   740  func TestCloudFrontStructure_flattenCustomHeaders(t *testing.T) {
   741  	in := originCustomHeadersConf()
   742  	chs := expandCustomHeaders(in)
   743  	out := flattenCustomHeaders(chs)
   744  	diff := in.Difference(out)
   745  
   746  	if len(diff.List()) > 0 {
   747  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   748  	}
   749  }
   750  
   751  func TestCloudFrontStructure_flattenOriginCustomHeader(t *testing.T) {
   752  	in := originCustomHeaderConf1()
   753  	och := expandOriginCustomHeader(in)
   754  	out := flattenOriginCustomHeader(och)
   755  
   756  	if out["name"] != "X-Custom-Header1" {
   757  		t.Fatalf("Expected out[name] to be X-Custom-Header1, got %v", out["name"])
   758  	}
   759  	if out["value"] != "samplevalue" {
   760  		t.Fatalf("Expected out[value] to be samplevalue, got %v", out["value"])
   761  	}
   762  }
   763  
   764  func TestCloudFrontStructure_expandOriginCustomHeader(t *testing.T) {
   765  	in := originCustomHeaderConf1()
   766  	och := expandOriginCustomHeader(in)
   767  
   768  	if *och.HeaderName != "X-Custom-Header1" {
   769  		t.Fatalf("Expected HeaderName to be X-Custom-Header1, got %v", *och.HeaderName)
   770  	}
   771  	if *och.HeaderValue != "samplevalue" {
   772  		t.Fatalf("Expected HeaderValue to be samplevalue, got %v", *och.HeaderValue)
   773  	}
   774  }
   775  
   776  func TestCloudFrontStructure_expandCustomOriginConfig(t *testing.T) {
   777  	data := customOriginConf()
   778  	co := expandCustomOriginConfig(data)
   779  	if *co.OriginProtocolPolicy != "http-only" {
   780  		t.Fatalf("Expected OriginProtocolPolicy to be http-only, got %v", *co.OriginProtocolPolicy)
   781  	}
   782  	if *co.HTTPPort != 80 {
   783  		t.Fatalf("Expected HTTPPort to be 80, got %v", *co.HTTPPort)
   784  	}
   785  	if *co.HTTPSPort != 443 {
   786  		t.Fatalf("Expected HTTPSPort to be 443, got %v", *co.HTTPSPort)
   787  	}
   788  }
   789  
   790  func TestCloudFrontStructure_flattenCustomOriginConfig(t *testing.T) {
   791  	in := customOriginConf()
   792  	co := expandCustomOriginConfig(in)
   793  	out := flattenCustomOriginConfig(co)
   794  
   795  	if reflect.DeepEqual(in, out) != true {
   796  		t.Fatalf("Expected out to be %v, got %v", in, out)
   797  	}
   798  }
   799  
   800  func TestCloudFrontStructure_expandCustomOriginConfigSSL(t *testing.T) {
   801  	in := customOriginSslProtocolsConf()
   802  	ocs := expandCustomOriginConfigSSL(in)
   803  	if *ocs.Quantity != 4 {
   804  		t.Fatalf("Expected Quantity to be 4, got %v", *ocs.Quantity)
   805  	}
   806  	if *ocs.Items[0] != "SSLv3" {
   807  		t.Fatalf("Expected first Item to be SSLv3, got %v", *ocs.Items[0])
   808  	}
   809  }
   810  
   811  func TestCloudFrontStructure_flattenCustomOriginConfigSSL(t *testing.T) {
   812  	in := customOriginSslProtocolsConf()
   813  	ocs := expandCustomOriginConfigSSL(in)
   814  	out := flattenCustomOriginConfigSSL(ocs)
   815  
   816  	if reflect.DeepEqual(in, out) != true {
   817  		t.Fatalf("Expected out to be %v, got %v", in, out)
   818  	}
   819  }
   820  
   821  func TestCloudFrontStructure_expandS3OriginConfig(t *testing.T) {
   822  	data := s3OriginConf()
   823  	s3o := expandS3OriginConfig(data)
   824  	if *s3o.OriginAccessIdentity != "origin-access-identity/cloudfront/E127EXAMPLE51Z" {
   825  		t.Fatalf("Expected OriginAccessIdentity to be origin-access-identity/cloudfront/E127EXAMPLE51Z, got %v", *s3o.OriginAccessIdentity)
   826  	}
   827  }
   828  
   829  func TestCloudFrontStructure_flattenS3OriginConfig(t *testing.T) {
   830  	in := s3OriginConf()
   831  	s3o := expandS3OriginConfig(in)
   832  	out := flattenS3OriginConfig(s3o)
   833  
   834  	if reflect.DeepEqual(in, out) != true {
   835  		t.Fatalf("Expected out to be %v, got %v", in, out)
   836  	}
   837  }
   838  
   839  func TestCloudFrontStructure_expandCustomErrorResponses(t *testing.T) {
   840  	data := customErrorResponsesConfSet()
   841  	ers := expandCustomErrorResponses(data)
   842  	if *ers.Quantity != 2 {
   843  		t.Fatalf("Expected Quantity to be 2, got %v", *ers.Quantity)
   844  	}
   845  	if *ers.Items[0].ResponsePagePath != "/error-pages/404.html" {
   846  		t.Fatalf("Expected ResponsePagePath in first Item to be /error-pages/404.html, got %v", *ers.Items[0].ResponsePagePath)
   847  	}
   848  }
   849  
   850  func TestCloudFrontStructure_flattenCustomErrorResponses(t *testing.T) {
   851  	in := customErrorResponsesConfSet()
   852  	ers := expandCustomErrorResponses(in)
   853  	out := flattenCustomErrorResponses(ers)
   854  
   855  	if in.Equal(out) != true {
   856  		t.Fatalf("Expected out to be %v, got %v", in, out)
   857  	}
   858  }
   859  
   860  func TestCloudFrontStructure_expandCustomErrorResponse(t *testing.T) {
   861  	data := customErrorResponsesConfFirst()
   862  	er := expandCustomErrorResponse(data)
   863  	if *er.ErrorCode != 404 {
   864  		t.Fatalf("Expected ErrorCode to be 404, got %v", *er.ErrorCode)
   865  	}
   866  	if *er.ErrorCachingMinTTL != 30 {
   867  		t.Fatalf("Expected ErrorCachingMinTTL to be 30, got %v", *er.ErrorCachingMinTTL)
   868  	}
   869  	if *er.ResponseCode != "200" {
   870  		t.Fatalf("Expected ResponseCode to be 200 (as string), got %v", *er.ResponseCode)
   871  	}
   872  	if *er.ResponsePagePath != "/error-pages/404.html" {
   873  		t.Fatalf("Expected ResponsePagePath to be /error-pages/404.html, got %v", *er.ResponsePagePath)
   874  	}
   875  }
   876  
   877  func TestCloudFrontStructure_expandCustomErrorResponse_emptyResponseCode(t *testing.T) {
   878  	data := customErrorResponseConfNoResponseCode()
   879  	er := expandCustomErrorResponse(data)
   880  	if *er.ResponseCode != "" {
   881  		t.Fatalf("Expected ResponseCode to be empty string, got %v", *er.ResponseCode)
   882  	}
   883  	if *er.ResponsePagePath != "" {
   884  		t.Fatalf("Expected ResponsePagePath to be empty string, got %v", *er.ResponsePagePath)
   885  	}
   886  }
   887  
   888  func TestCloudFrontStructure_flattenCustomErrorResponse(t *testing.T) {
   889  	in := customErrorResponsesConfFirst()
   890  	er := expandCustomErrorResponse(in)
   891  	out := flattenCustomErrorResponse(er)
   892  
   893  	if reflect.DeepEqual(in, out) != true {
   894  		t.Fatalf("Expected out to be %v, got %v", in, out)
   895  	}
   896  }
   897  
   898  func TestCloudFrontStructure_expandLoggingConfig(t *testing.T) {
   899  	data := loggingConfigConf()
   900  
   901  	lc := expandLoggingConfig(data)
   902  	if *lc.Enabled != true {
   903  		t.Fatalf("Expected Enabled to be true, got %v", *lc.Enabled)
   904  	}
   905  	if *lc.Prefix != "myprefix" {
   906  		t.Fatalf("Expected Prefix to be myprefix, got %v", *lc.Prefix)
   907  	}
   908  	if *lc.Bucket != "mylogs.s3.amazonaws.com" {
   909  		t.Fatalf("Expected Bucket to be mylogs.s3.amazonaws.com, got %v", *lc.Bucket)
   910  	}
   911  	if *lc.IncludeCookies != false {
   912  		t.Fatalf("Expected IncludeCookies to be false, got %v", *lc.IncludeCookies)
   913  	}
   914  }
   915  
   916  func TestCloudFrontStructure_expandLoggingConfig_nilValue(t *testing.T) {
   917  	lc := expandLoggingConfig(nil)
   918  	if *lc.Enabled != false {
   919  		t.Fatalf("Expected Enabled to be false, got %v", *lc.Enabled)
   920  	}
   921  	if *lc.Prefix != "" {
   922  		t.Fatalf("Expected Prefix to be blank, got %v", *lc.Prefix)
   923  	}
   924  	if *lc.Bucket != "" {
   925  		t.Fatalf("Expected Bucket to be blank, got %v", *lc.Bucket)
   926  	}
   927  	if *lc.IncludeCookies != false {
   928  		t.Fatalf("Expected IncludeCookies to be false, got %v", *lc.IncludeCookies)
   929  	}
   930  }
   931  
   932  func TestCloudFrontStructure_flattenLoggingConfig(t *testing.T) {
   933  	in := loggingConfigConf()
   934  	lc := expandLoggingConfig(in)
   935  	out := flattenLoggingConfig(lc)
   936  	diff := schema.NewSet(loggingConfigHash, []interface{}{in}).Difference(out)
   937  
   938  	if len(diff.List()) > 0 {
   939  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   940  	}
   941  }
   942  
   943  func TestCloudFrontStructure_expandAliases(t *testing.T) {
   944  	data := aliasesConf()
   945  	a := expandAliases(data)
   946  	if *a.Quantity != 2 {
   947  		t.Fatalf("Expected Quantity to be 2, got %v", *a.Quantity)
   948  	}
   949  	if reflect.DeepEqual(a.Items, expandStringList(data.List())) != true {
   950  		t.Fatalf("Expected Items to be [example.com www.example.com], got %v", a.Items)
   951  	}
   952  }
   953  
   954  func TestCloudFrontStructure_flattenAliases(t *testing.T) {
   955  	in := aliasesConf()
   956  	a := expandAliases(in)
   957  	out := flattenAliases(a)
   958  	diff := in.Difference(out)
   959  
   960  	if len(diff.List()) > 0 {
   961  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   962  	}
   963  }
   964  
   965  func TestCloudFrontStructure_expandRestrictions(t *testing.T) {
   966  	data := geoRestrictionsConf()
   967  	r := expandRestrictions(data)
   968  	if *r.GeoRestriction.RestrictionType != "whitelist" {
   969  		t.Fatalf("Expected GeoRestriction.RestrictionType to be whitelist, got %v", *r.GeoRestriction.RestrictionType)
   970  	}
   971  }
   972  
   973  func TestCloudFrontStructure_flattenRestrictions(t *testing.T) {
   974  	in := geoRestrictionsConf()
   975  	r := expandRestrictions(in)
   976  	out := flattenRestrictions(r)
   977  	diff := schema.NewSet(restrictionsHash, []interface{}{in}).Difference(out)
   978  
   979  	if len(diff.List()) > 0 {
   980  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
   981  	}
   982  }
   983  
   984  func TestCloudFrontStructure_expandGeoRestriction_whitelist(t *testing.T) {
   985  	data := geoRestrictionWhitelistConf()
   986  	gr := expandGeoRestriction(data)
   987  	if *gr.RestrictionType != "whitelist" {
   988  		t.Fatalf("Expected RestrictionType to be whitelist, got %v", *gr.RestrictionType)
   989  	}
   990  	if *gr.Quantity != 3 {
   991  		t.Fatalf("Expected Quantity to be 3, got %v", *gr.Quantity)
   992  	}
   993  	if reflect.DeepEqual(gr.Items, aws.StringSlice([]string{"CA", "GB", "US"})) != true {
   994  		t.Fatalf("Expected Items be [CA, GB, US], got %v", gr.Items)
   995  	}
   996  }
   997  
   998  func TestCloudFrontStructure_flattenGeoRestriction_whitelist(t *testing.T) {
   999  	in := geoRestrictionWhitelistConf()
  1000  	gr := expandGeoRestriction(in)
  1001  	out := flattenGeoRestriction(gr)
  1002  
  1003  	if reflect.DeepEqual(in, out) != true {
  1004  		t.Fatalf("Expected out to be %v, got %v", in, out)
  1005  	}
  1006  }
  1007  
  1008  func TestCloudFrontStructure_expandGeoRestriction_no_items(t *testing.T) {
  1009  	data := geoRestrictionConfNoItems()
  1010  	gr := expandGeoRestriction(data)
  1011  	if *gr.RestrictionType != "none" {
  1012  		t.Fatalf("Expected RestrictionType to be none, got %v", *gr.RestrictionType)
  1013  	}
  1014  	if *gr.Quantity != 0 {
  1015  		t.Fatalf("Expected Quantity to be 0, got %v", *gr.Quantity)
  1016  	}
  1017  	if gr.Items != nil {
  1018  		t.Fatalf("Expected Items to not be set, got %v", gr.Items)
  1019  	}
  1020  }
  1021  
  1022  func TestCloudFrontStructure_flattenGeoRestriction_no_items(t *testing.T) {
  1023  	in := geoRestrictionConfNoItems()
  1024  	gr := expandGeoRestriction(in)
  1025  	out := flattenGeoRestriction(gr)
  1026  
  1027  	if reflect.DeepEqual(in, out) != true {
  1028  		t.Fatalf("Expected out to be %v, got %v", in, out)
  1029  	}
  1030  }
  1031  
  1032  func TestCloudFrontStructure_expandViewerCertificate_cloudfront_default_certificate(t *testing.T) {
  1033  	data := viewerCertificateConfSetCloudFrontDefault()
  1034  	vc := expandViewerCertificate(data)
  1035  	if vc.ACMCertificateArn != nil {
  1036  		t.Fatalf("Expected ACMCertificateArn to be unset, got %v", *vc.ACMCertificateArn)
  1037  	}
  1038  	if *vc.CloudFrontDefaultCertificate != true {
  1039  		t.Fatalf("Expected CloudFrontDefaultCertificate to be true, got %v", *vc.CloudFrontDefaultCertificate)
  1040  	}
  1041  	if vc.IAMCertificateId != nil {
  1042  		t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.IAMCertificateId)
  1043  	}
  1044  	if vc.SSLSupportMethod != nil {
  1045  		t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.SSLSupportMethod)
  1046  	}
  1047  	if vc.MinimumProtocolVersion != nil {
  1048  		t.Fatalf("Expected IAMCertificateId to not be set, got %v", *vc.MinimumProtocolVersion)
  1049  	}
  1050  }
  1051  
  1052  func TestCloudFrontStructure_flattenViewerCertificate_cloudfront_default_certificate(t *testing.T) {
  1053  	in := viewerCertificateConfSetCloudFrontDefault()
  1054  	vc := expandViewerCertificate(in)
  1055  	out := flattenViewerCertificate(vc)
  1056  	diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out)
  1057  
  1058  	if len(diff.List()) > 0 {
  1059  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
  1060  	}
  1061  }
  1062  
  1063  func TestCloudFrontStructure_expandViewerCertificate_iam_certificate_id(t *testing.T) {
  1064  	data := viewerCertificateConfSetIAM()
  1065  	vc := expandViewerCertificate(data)
  1066  	if vc.ACMCertificateArn != nil {
  1067  		t.Fatalf("Expected ACMCertificateArn to be unset, got %v", *vc.ACMCertificateArn)
  1068  	}
  1069  	if vc.CloudFrontDefaultCertificate != nil {
  1070  		t.Fatalf("Expected CloudFrontDefaultCertificate to be unset, got %v", *vc.CloudFrontDefaultCertificate)
  1071  	}
  1072  	if *vc.IAMCertificateId != "iamcert-01234567" {
  1073  		t.Fatalf("Expected IAMCertificateId to be iamcert-01234567, got %v", *vc.IAMCertificateId)
  1074  	}
  1075  	if *vc.SSLSupportMethod != "vip" {
  1076  		t.Fatalf("Expected IAMCertificateId to be vip, got %v", *vc.SSLSupportMethod)
  1077  	}
  1078  	if *vc.MinimumProtocolVersion != "TLSv1" {
  1079  		t.Fatalf("Expected IAMCertificateId to be TLSv1, got %v", *vc.MinimumProtocolVersion)
  1080  	}
  1081  }
  1082  
  1083  func TestCloudFrontStructure_expandViewerCertificate_acm_certificate_arn(t *testing.T) {
  1084  	data := viewerCertificateConfSetACM()
  1085  	vc := expandViewerCertificate(data)
  1086  	if *vc.ACMCertificateArn != "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" {
  1087  		t.Fatalf("Expected ACMCertificateArn to be arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012, got %v", *vc.ACMCertificateArn)
  1088  	}
  1089  	if vc.CloudFrontDefaultCertificate != nil {
  1090  		t.Fatalf("Expected CloudFrontDefaultCertificate to be unset, got %v", *vc.CloudFrontDefaultCertificate)
  1091  	}
  1092  	if vc.IAMCertificateId != nil {
  1093  		t.Fatalf("Expected IAMCertificateId to be unset, got %v", *vc.IAMCertificateId)
  1094  	}
  1095  	if *vc.SSLSupportMethod != "sni-only" {
  1096  		t.Fatalf("Expected IAMCertificateId to be sni-only, got %v", *vc.SSLSupportMethod)
  1097  	}
  1098  	if *vc.MinimumProtocolVersion != "TLSv1" {
  1099  		t.Fatalf("Expected IAMCertificateId to be TLSv1, got %v", *vc.MinimumProtocolVersion)
  1100  	}
  1101  }
  1102  
  1103  func TestCloudFrontStructure_falttenViewerCertificate_iam_certificate_id(t *testing.T) {
  1104  	in := viewerCertificateConfSetIAM()
  1105  	vc := expandViewerCertificate(in)
  1106  	out := flattenViewerCertificate(vc)
  1107  	diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out)
  1108  
  1109  	if len(diff.List()) > 0 {
  1110  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
  1111  	}
  1112  }
  1113  
  1114  func TestCloudFrontStructure_falttenViewerCertificate_acm_certificate_arn(t *testing.T) {
  1115  	in := viewerCertificateConfSetACM()
  1116  	vc := expandViewerCertificate(in)
  1117  	out := flattenViewerCertificate(vc)
  1118  	diff := schema.NewSet(viewerCertificateHash, []interface{}{in}).Difference(out)
  1119  
  1120  	if len(diff.List()) > 0 {
  1121  		t.Fatalf("Expected out to be %v, got %v, diff: %v", in, out, diff)
  1122  	}
  1123  }
  1124  
  1125  func TestCloudFrontStructure_viewerCertificateHash_IAM(t *testing.T) {
  1126  	in := viewerCertificateConfSetIAM()
  1127  	out := viewerCertificateHash(in)
  1128  	expected := 1157261784
  1129  
  1130  	if expected != out {
  1131  		t.Fatalf("Expected %v, got %v", expected, out)
  1132  	}
  1133  }
  1134  
  1135  func TestCloudFrontStructure_viewerCertificateHash_ACM(t *testing.T) {
  1136  	in := viewerCertificateConfSetACM()
  1137  	out := viewerCertificateHash(in)
  1138  	expected := 2883600425
  1139  
  1140  	if expected != out {
  1141  		t.Fatalf("Expected %v, got %v", expected, out)
  1142  	}
  1143  }
  1144  
  1145  func TestCloudFrontStructure_viewerCertificateHash_default(t *testing.T) {
  1146  	in := viewerCertificateConfSetCloudFrontDefault()
  1147  	out := viewerCertificateHash(in)
  1148  	expected := 69840937
  1149  
  1150  	if expected != out {
  1151  		t.Fatalf("Expected %v, got %v", expected, out)
  1152  	}
  1153  }