2015-03-24 19:37:42 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2016-06-21 17:33:12 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/elb"
|
2015-03-24 19:37:42 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDiffELBTags(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Old, New map[string]interface{}
|
|
|
|
Create, Remove map[string]string
|
|
|
|
}{
|
|
|
|
// Basic add/remove
|
|
|
|
{
|
|
|
|
Old: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
New: map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Create: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Remove: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Modify
|
|
|
|
{
|
|
|
|
Old: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
New: map[string]interface{}{
|
|
|
|
"foo": "baz",
|
|
|
|
},
|
|
|
|
Create: map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
},
|
|
|
|
Remove: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
c, r := diffTagsELB(tagsFromMapELB(tc.Old), tagsFromMapELB(tc.New))
|
|
|
|
cm := tagsToMapELB(c)
|
|
|
|
rm := tagsToMapELB(r)
|
|
|
|
if !reflect.DeepEqual(cm, tc.Create) {
|
|
|
|
t.Fatalf("%d: bad create: %#v", i, cm)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(rm, tc.Remove) {
|
|
|
|
t.Fatalf("%d: bad remove: %#v", i, rm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:33:12 +02:00
|
|
|
func TestIgnoringTagsELB(t *testing.T) {
|
|
|
|
var ignoredTags []*elb.Tag
|
|
|
|
ignoredTags = append(ignoredTags, &elb.Tag{
|
|
|
|
Key: aws.String("aws:cloudformation:logical-id"),
|
|
|
|
Value: aws.String("foo"),
|
|
|
|
})
|
|
|
|
ignoredTags = append(ignoredTags, &elb.Tag{
|
|
|
|
Key: aws.String("aws:foo:bar"),
|
|
|
|
Value: aws.String("baz"),
|
|
|
|
})
|
|
|
|
for _, tag := range ignoredTags {
|
|
|
|
if !tagIgnoredELB(tag) {
|
|
|
|
t.Fatalf("Tag %v with value %v not ignored, but should be!", *tag.Key, *tag.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:37:42 +01:00
|
|
|
// testAccCheckTags can be used to check the tags on a resource.
|
|
|
|
func testAccCheckELBTags(
|
2015-04-14 23:41:36 +02:00
|
|
|
ts *[]*elb.Tag, key string, value string) resource.TestCheckFunc {
|
2015-03-24 19:37:42 +01:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
m := tagsToMapELB(*ts)
|
|
|
|
v, ok := m[key]
|
|
|
|
if value != "" && !ok {
|
|
|
|
return fmt.Errorf("Missing tag: %s", key)
|
|
|
|
} else if value == "" && ok {
|
|
|
|
return fmt.Errorf("Extra tag: %s", key)
|
|
|
|
}
|
|
|
|
if value == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if v != value {
|
|
|
|
return fmt.Errorf("%s: bad value: %s", key, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|