github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/digitalocean/tags_test.go (about)

     1  package digitalocean
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestDiffTags(t *testing.T) {
     9  	cases := []struct {
    10  		Old, New       []interface{}
    11  		Create, Remove map[string]string
    12  	}{
    13  		// Basic add/remove
    14  		{
    15  			Old: []interface{}{
    16  				"foo",
    17  			},
    18  			New: []interface{}{
    19  				"bar",
    20  			},
    21  			Create: map[string]string{
    22  				"bar": "bar",
    23  			},
    24  			Remove: map[string]string{
    25  				"foo": "foo",
    26  			},
    27  		},
    28  
    29  		// Noop
    30  		{
    31  			Old: []interface{}{
    32  				"foo",
    33  			},
    34  			New: []interface{}{
    35  				"foo",
    36  			},
    37  			Create: map[string]string{},
    38  			Remove: map[string]string{},
    39  		},
    40  	}
    41  
    42  	for i, tc := range cases {
    43  		r, c := diffTags(tagsFromSchema(tc.Old), tagsFromSchema(tc.New))
    44  		if !reflect.DeepEqual(r, tc.Remove) {
    45  			t.Fatalf("%d: bad remove: %#v", i, r)
    46  		}
    47  		if !reflect.DeepEqual(c, tc.Create) {
    48  			t.Fatalf("%d: bad create: %#v", i, c)
    49  		}
    50  	}
    51  }