diff --git a/mapper/mock_test.go b/mapper/mock_test.go index bc643d1..5ed0416 100644 --- a/mapper/mock_test.go +++ b/mapper/mock_test.go @@ -11,23 +11,59 @@ func dummyMockMapperFct(res *string, tag []*TagItem) error { func TestMockRetag(t *testing.T) { testData := []struct { - inputResourceTags, outputResourceTags map[string]map[string]string - inputResourceKeys, outputResourceKeys map[string][]string + existingTags, inputResourceTags, outputResourceTags map[string]map[string]string + existingKeys, inputResourceKeys, outputResourceKeys map[string][]string }{ - {map[string]map[string]string{}, nil, map[string][]string{}, nil}, + {nil, map[string]map[string]string{}, nil, nil, map[string][]string{}, nil}, { map[string]map[string]string{"foo": {"key1": "value1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + map[string]map[string]string{}, map[string]map[string]string{"foo": {"key1": "value1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + map[string][]string{"joe": {"mykey4"}, "bar": {"key3"}}, + map[string][]string{}, + map[string][]string{"joe": {"mykey4"}, "bar": {"key3"}}, + }, + { + map[string]map[string]string{"foo": {"key1": "value1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + map[string]map[string]string{"foo": {"tofoo1": "spicy1"}}, + map[string]map[string]string{"foo": {"key1": "value1", "tofoo1": "spicy1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + map[string][]string{"joe": {"mykey4"}, "bar": {"key6"}}, + map[string][]string{"joe": {"mykey4"}, "bar": {"key3", "key8"}}, + map[string][]string{"foo": nil, "joe": {"mykey4", "mykey4"}, "bar": {"key6", "key3", "key8"}}, + }, + { + nil, + map[string]map[string]string{"foo": {"key1": "value1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + map[string]map[string]string{"foo": {"key1": "value1"}, "bar": {"key2": "value2", "key3": "value3"}, "joe": nil}, + nil, map[string][]string{"bar": {"mykey1", "mykey2"}, "joe": {"mykey3"}}, map[string][]string{"foo": nil, "bar": {"mykey1", "mykey2"}, "joe": {"mykey3"}}, }, } for _, d := range testData { - m := MockMapper{} - for k, v := range d.inputResourceTags { - inKeys := []string{} - inKeys, _ = d.inputResourceKeys[k] + m := MockMapper{ResourceTags: d.existingTags, ResourceKeys: d.existingKeys} + resources := []string{} + for k := range d.inputResourceTags { + resources = append(resources, k) + } + for k := range d.inputResourceKeys { + // Only add if not already there + found := false + for _, rez := range resources { + if rez == k { + found = true + break + } + } + if !found { + resources = append(resources, k) + } + } + for _, k := range resources { + v, _ := d.inputResourceTags[k] + inKeys, _ := d.inputResourceKeys[k] + t.Logf("%s, %v, %v", k, v, inKeys) m.Retag(&k, &v, inKeys, nil) } if !reflect.DeepEqual(d.outputResourceTags, m.ResourceTags) {