2016-05-24 19:43:12 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2016-06-21 17:33:12 +02:00
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/redshift"
|
2016-05-24 19:43:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDiffRedshiftTags(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Old, New map[string]interface{}
|
|
|
|
Create, Remove map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Old: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
New: map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Create: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Remove: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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 := diffTagsRedshift(tagsFromMapRedshift(tc.Old), tagsFromMapRedshift(tc.New))
|
|
|
|
cm := tagsToMapRedshift(c)
|
|
|
|
rm := tagsToMapRedshift(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 TestIgnoringTagsRedshift(t *testing.T) {
|
|
|
|
var ignoredTags []*redshift.Tag
|
|
|
|
ignoredTags = append(ignoredTags, &redshift.Tag{
|
|
|
|
Key: aws.String("aws:cloudformation:logical-id"),
|
|
|
|
Value: aws.String("foo"),
|
|
|
|
})
|
|
|
|
ignoredTags = append(ignoredTags, &redshift.Tag{
|
|
|
|
Key: aws.String("aws:foo:bar"),
|
|
|
|
Value: aws.String("baz"),
|
|
|
|
})
|
|
|
|
for _, tag := range ignoredTags {
|
|
|
|
if !tagIgnoredRedshift(tag) {
|
|
|
|
t.Fatalf("Tag %v with value %v not ignored, but should be!", *tag.Key, *tag.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|