provider/aws: Fix flattened cloudfront lambda function associations to be a set, not a slice (#11984)

This commit is contained in:
Jake Pusateri 2017-03-20 06:05:19 -07:00 committed by Paul Stack
parent 4d70f4539d
commit c7546c7726
2 changed files with 7 additions and 13 deletions

View File

@ -443,10 +443,10 @@ func expandLambdaFunctionAssociation(lf map[string]interface{}) *cloudfront.Lamb
return &lfa return &lfa
} }
func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) []interface{} { func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) *schema.Set {
s := make([]interface{}, len(lfa.Items)) s := schema.NewSet(lambdaFunctionAssociationHash, []interface{}{})
for i, v := range lfa.Items { for _, v := range lfa.Items {
s[i] = flattenLambdaFunctionAssociation(v) s.Add(flattenLambdaFunctionAssociation(v))
} }
return s return s
} }

View File

@ -364,14 +364,8 @@ func TestCloudFrontStructure_flattenCacheBehavior(t *testing.T) {
t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"]) t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"])
} }
// the flattened lambda function associations are a slice of maps, var outSet, ok = out["lambda_function_association"].(*schema.Set)
// where as the default cache behavior LFAs are a set. Here we double check if !ok {
// that and conver the slice to a set, and use Set's Equal() method to check
// equality
var outSet *schema.Set
if outSlice, ok := out["lambda_function_association"].([]interface{}); ok {
outSet = schema.NewSet(lambdaFunctionAssociationHash, outSlice)
} else {
t.Fatalf("out['lambda_function_association'] is not a slice as expected: %#v", out["lambda_function_association"]) t.Fatalf("out['lambda_function_association'] is not a slice as expected: %#v", out["lambda_function_association"])
} }
@ -496,7 +490,7 @@ func TestCloudFrontStructure_flattenlambdaFunctionAssociations(t *testing.T) {
lfa := expandLambdaFunctionAssociations(in.List()) lfa := expandLambdaFunctionAssociations(in.List())
out := flattenLambdaFunctionAssociations(lfa) out := flattenLambdaFunctionAssociations(lfa)
if reflect.DeepEqual(in.List(), out) != true { if reflect.DeepEqual(in.List(), out.List()) != true {
t.Fatalf("Expected out to be %v, got %v", in, out) t.Fatalf("Expected out to be %v, got %v", in, out)
} }
} }