From 9353bd8f600ac4f7b8dc5b4565c966e5a425107f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 15 Oct 2017 17:18:12 +0000 Subject: [PATCH] Add TestSetsDelete() --- report/sets_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/report/sets_test.go b/report/sets_test.go index c2ac164fb..1ffde64ed 100644 --- a/report/sets_test.go +++ b/report/sets_test.go @@ -7,6 +7,36 @@ import ( "github.com/weaveworks/scope/test/reflect" ) +func TestSetsDelete(t *testing.T) { + aSet := report.MakeSets().Add("a", report.MakeStringSet("a")) + for _, testcase := range []struct { + input report.Sets + key string + want report.Sets + }{ + {key: "", input: report.Sets{}, want: report.Sets{}}, + {key: "", input: report.MakeSets(), want: report.MakeSets()}, + {key: "", input: aSet, want: aSet}, + {key: "a", input: report.MakeSets(), want: report.MakeSets()}, + {key: "a", input: aSet, want: report.MakeSets()}, + {key: "b", input: aSet, want: aSet}, + {key: "b", input: aSet.Add("b", report.MakeStringSet("b")), want: aSet}, + { + input: aSet.Add("b", report.MakeStringSet("b")), + key: "a", + want: report.MakeSets().Add("b", report.MakeStringSet("b")), + }, + } { + originalLen := testcase.input.Size() + if want, have := testcase.want, testcase.input.Delete(testcase.key); !reflect.DeepEqual(want, have) { + t.Errorf("%v - %v: want %v, have %v", testcase.input, testcase.key, want, have) + } + if testcase.input.Size() != originalLen { + t.Errorf("%v - %v: modified the original input!", testcase.input, testcase.key) + } + } +} + func TestSetsMerge(t *testing.T) { for _, testcase := range []struct { a, b report.Sets