From 3d04c6c5ce5d019e3a1f58354ab9f67453a83f8a Mon Sep 17 00:00:00 2001 From: jabielecki <47531708+jabielecki@users.noreply.github.com> Date: Thu, 12 Dec 2019 12:41:55 +0100 Subject: [PATCH] ref(pkg/action): split test of filterList (#6875) The existing unit test doesn't cover the most important functionality of filterList(). Adding that check. Separately test the specific namespace-related behavior. Remove the dead variable anotherOldOne. Signed-off-by: Jakub Bielecki --- pkg/action/list_test.go | 55 ++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/pkg/action/list_test.go b/pkg/action/list_test.go index cd86aee68..378a747b0 100644 --- a/pkg/action/list_test.go +++ b/pkg/action/list_test.go @@ -237,27 +237,36 @@ func makeMeSomeReleases(store *storage.Storage, t *testing.T) { } func TestFilterList(t *testing.T) { - one := releaseStub() - one.Name = "one" - one.Namespace = "default" - one.Version = 1 - two := releaseStub() - two.Name = "two" - two.Namespace = "default" - two.Version = 1 - anotherOldOne := releaseStub() - anotherOldOne.Name = "one" - anotherOldOne.Namespace = "testing" - anotherOldOne.Version = 1 - anotherOne := releaseStub() - anotherOne.Name = "one" - anotherOne.Namespace = "testing" - anotherOne.Version = 2 - - list := []*release.Release{one, two, anotherOne} - expectedFilteredList := []*release.Release{one, two, anotherOne} - - filteredList := filterList(list) - - assert.ElementsMatch(t, expectedFilteredList, filteredList) + t.Run("should filter old versions of the same release", func(t *testing.T) { + r1 := releaseStub() + r1.Name = "r" + r1.Version = 1 + r2 := releaseStub() + r2.Name = "r" + r2.Version = 2 + another := releaseStub() + another.Name = "another" + another.Version = 1 + + filteredList := filterList([]*release.Release{r1, r2, another}) + expectedFilteredList := []*release.Release{r2, another} + + assert.ElementsMatch(t, expectedFilteredList, filteredList) + }) + + t.Run("should not filter out any version across namespaces", func(t *testing.T) { + r1 := releaseStub() + r1.Name = "r" + r1.Namespace = "default" + r1.Version = 1 + r2 := releaseStub() + r2.Name = "r" + r2.Namespace = "testing" + r2.Version = 2 + + filteredList := filterList([]*release.Release{r1, r2}) + expectedFilteredList := []*release.Release{r1, r2} + + assert.ElementsMatch(t, expectedFilteredList, filteredList) + }) }