Skip to content

Commit

Permalink
Merge pull request #10 from VEVO/mock_test
Browse files Browse the repository at this point in the history
Fix MockMapper.Retag test logic
  • Loading branch information
aerostitch authored Jan 5, 2018
2 parents 699542b + 0ef93f3 commit c958e91
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions mapper/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c958e91

Please sign in to comment.