github.com/gabrielperezs/terraform@v0.7.0-rc2.0.20160715084931-f7da2612946f/builtin/providers/cloudstack/tags_test.go (about) 1 package cloudstack 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 ) 8 9 func TestDiffTags(t *testing.T) { 10 cases := []struct { 11 Old, New map[string]interface{} 12 Create, Remove map[string]string 13 }{ 14 // Basic add/remove 15 { 16 Old: map[string]interface{}{ 17 "foo": "bar", 18 }, 19 New: map[string]interface{}{ 20 "bar": "baz", 21 }, 22 Create: map[string]string{ 23 "bar": "baz", 24 }, 25 Remove: map[string]string{ 26 "foo": "bar", 27 }, 28 }, 29 30 // Modify 31 { 32 Old: map[string]interface{}{ 33 "foo": "bar", 34 }, 35 New: map[string]interface{}{ 36 "foo": "baz", 37 }, 38 Create: map[string]string{ 39 "foo": "baz", 40 }, 41 Remove: map[string]string{ 42 "foo": "bar", 43 }, 44 }, 45 } 46 47 for i, tc := range cases { 48 r, c := diffTags(tagsFromSchema(tc.Old), tagsFromSchema(tc.New)) 49 if !reflect.DeepEqual(r, tc.Remove) { 50 t.Fatalf("%d: bad remove: %#v", i, r) 51 } 52 if !reflect.DeepEqual(c, tc.Create) { 53 t.Fatalf("%d: bad create: %#v", i, c) 54 } 55 } 56 } 57 58 // testAccCheckTags can be used to check the tags on a resource. 59 func testAccCheckTags(tags map[string]string, key string, value string) error { 60 v, ok := tags[key] 61 if !ok { 62 return fmt.Errorf("Missing tag: %s", key) 63 } 64 65 if v != value { 66 return fmt.Errorf("%s: bad value: %s", key, v) 67 } 68 69 return nil 70 }