From 9f01efae6f027ce6cd646ebb7c018f95a410104d Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 5 Oct 2015 11:24:09 +0100 Subject: [PATCH] Adding a test to make sure that the diffGlacierVaultTags func works as expected --- .../aws/resource_aws_glacier_vault_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/builtin/providers/aws/resource_aws_glacier_vault_test.go b/builtin/providers/aws/resource_aws_glacier_vault_test.go index fc5e150d9..4f5c26bf2 100644 --- a/builtin/providers/aws/resource_aws_glacier_vault_test.go +++ b/builtin/providers/aws/resource_aws_glacier_vault_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "reflect" "testing" "github.com/aws/aws-sdk-go/aws" @@ -67,6 +68,57 @@ func TestAccAWSGlacierVault_RemoveNotifications(t *testing.T) { }) } +func TestDiffGlacierVaultTags(t *testing.T) { + cases := []struct { + Old, New map[string]interface{} + Create map[string]string + Remove []string + }{ + // Basic add/remove + { + Old: map[string]interface{}{ + "foo": "bar", + }, + New: map[string]interface{}{ + "bar": "baz", + }, + Create: map[string]string{ + "bar": "baz", + }, + Remove: []string{ + "foo", + }, + }, + + // Modify + { + Old: map[string]interface{}{ + "foo": "bar", + }, + New: map[string]interface{}{ + "foo": "baz", + }, + Create: map[string]string{ + "foo": "baz", + }, + Remove: []string{ + "foo", + }, + }, + } + + for i, tc := range cases { + c, r := diffGlacierVaultTags(mapGlacierVaultTags(tc.Old), mapGlacierVaultTags(tc.New)) + + if !reflect.DeepEqual(c, tc.Create) { + t.Fatalf("%d: bad create: %#v", i, c) + } + if !reflect.DeepEqual(r, tc.Remove) { + t.Fatalf("%d: bad remove: %#v", i, r) + } + } +} + func testAccCheckGlacierVaultExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name]