From 9f6965d10f5c5f47d9708342754b08b89b7cd904 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Mon, 1 Jun 2020 16:47:35 +0200 Subject: [PATCH] add tests for skipKindsMap --- main.go | 4 +++- main_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 main_test.go diff --git a/main.go b/main.go index bb54261..2f19dc4 100644 --- a/main.go +++ b/main.go @@ -141,7 +141,9 @@ func skipKindsMap(skipKindsCSV string) map[string]bool { splitKinds := strings.Split(skipKindsCSV, ",") skipKinds := map[string]bool{} for _, kind := range splitKinds { - skipKinds[kind] = true + if len(kind) > 0 { + skipKinds[kind] = true + } } return skipKinds } diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..c5898d3 --- /dev/null +++ b/main_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "reflect" + "testing" +) + +func TestSkipKindMaps(t *testing.T) { + for _, testCase := range []struct { + name string + csvSkipKinds string + expect map[string]bool + } { + { + "nothing to skip", + "", + map[string]bool {}, + }, + { + "a single kind to skip", + "somekind", + map[string]bool { + "somekind": true, + }, + }, + { + "multiple kinds to skip", + "somekind,anotherkind,yetsomeotherkind", + map[string]bool { + "somekind": true, + "anotherkind": true, + "yetsomeotherkind": true, + }, + }, + } { + got := skipKindsMap(testCase.csvSkipKinds) + if !reflect.DeepEqual(got, testCase.expect) { + t.Errorf("%s - got %+v, expected %+v", testCase.name, got, testCase.expect) + } + } +} \ No newline at end of file