From 78487238fe1cc156c9fbb894b2170d3d1c23ca8d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 9 Jul 2018 20:20:13 +0000 Subject: [PATCH] Make TestSetsMerge() check both ways round --- report/sets_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/report/sets_test.go b/report/sets_test.go index c2ac164fb1..e8b8866988 100644 --- a/report/sets_test.go +++ b/report/sets_test.go @@ -1,6 +1,7 @@ package report_test import ( + "fmt" "testing" "github.com/weaveworks/scope/report" @@ -29,15 +30,19 @@ func TestSetsMerge(t *testing.T) { map[string][]string{"a": {"1"}, "b": {"2", "3"}, "c": {"3"}}, }, } { - haveSets := testcase.a.Merge(testcase.b) - have := map[string][]string{} - keys := haveSets.Keys() - for _, k := range keys { - have[k], _ = haveSets.Lookup(k) - } + check(t, fmt.Sprintf("%+v.Merge(%+v)", testcase.a, testcase.b), testcase.a.Merge(testcase.b), testcase.want) + check(t, fmt.Sprintf("%+v.Merge(%+v)", testcase.b, testcase.a), testcase.b.Merge(testcase.a), testcase.want) + } +} + +func check(t *testing.T, desc string, haveSets report.Sets, want map[string][]string) { + have := map[string][]string{} + keys := haveSets.Keys() + for _, k := range keys { + have[k], _ = haveSets.Lookup(k) + } - if !reflect.DeepEqual(testcase.want, have) { - t.Errorf("%+v.Merge(%+v): want %+v, have %+v", testcase.a, testcase.b, testcase.want, have) - } + if !reflect.DeepEqual(want, have) { + t.Errorf("%s: want %+v, have %+v", desc, want, have) } }