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 <jakub.bielecki@codilime.com>
pull/7227/head
jabielecki 5 years ago committed by Martin Hickey
parent 0cb0eaca94
commit 3d04c6c5ce

@ -237,27 +237,36 @@ func makeMeSomeReleases(store *storage.Storage, t *testing.T) {
} }
func TestFilterList(t *testing.T) { func TestFilterList(t *testing.T) {
one := releaseStub() t.Run("should filter old versions of the same release", func(t *testing.T) {
one.Name = "one" r1 := releaseStub()
one.Namespace = "default" r1.Name = "r"
one.Version = 1 r1.Version = 1
two := releaseStub() r2 := releaseStub()
two.Name = "two" r2.Name = "r"
two.Namespace = "default" r2.Version = 2
two.Version = 1 another := releaseStub()
anotherOldOne := releaseStub() another.Name = "another"
anotherOldOne.Name = "one" another.Version = 1
anotherOldOne.Namespace = "testing"
anotherOldOne.Version = 1 filteredList := filterList([]*release.Release{r1, r2, another})
anotherOne := releaseStub() expectedFilteredList := []*release.Release{r2, another}
anotherOne.Name = "one"
anotherOne.Namespace = "testing" assert.ElementsMatch(t, expectedFilteredList, filteredList)
anotherOne.Version = 2 })
list := []*release.Release{one, two, anotherOne} t.Run("should not filter out any version across namespaces", func(t *testing.T) {
expectedFilteredList := []*release.Release{one, two, anotherOne} r1 := releaseStub()
r1.Name = "r"
filteredList := filterList(list) r1.Namespace = "default"
r1.Version = 1
assert.ElementsMatch(t, expectedFilteredList, filteredList) 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)
})
} }

Loading…
Cancel
Save