diff --git a/pkg/agent/agent_test.go b/pkg/agent/agent_test.go index 7f2795e5218..9ab28ebc307 100644 --- a/pkg/agent/agent_test.go +++ b/pkg/agent/agent_test.go @@ -13,6 +13,7 @@ import ( "helm.sh/helm/v3/pkg/storage" "helm.sh/helm/v3/pkg/storage/driver" + "github.com/google/go-cmp/cmp" "github.com/kubeapps/kubeapps/pkg/proxy" ) @@ -89,8 +90,8 @@ func TestListReleases(t *testing.T) { namespace: "", listLimit: defaultListLimit, releases: []releaseStub{ - releaseStub{"wordpress", "default", 1}, releaseStub{"airwatch", "default", 1}, + releaseStub{"wordpress", "default", 1}, releaseStub{"not-in-default-namespace", "other", 1}, }, expectedApps: []proxy.AppOverview{ @@ -98,16 +99,22 @@ func TestListReleases(t *testing.T) { ReleaseName: "airwatch", Namespace: "default", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, proxy.AppOverview{ - ReleaseName: "wordpress", - Namespace: "default", + ReleaseName: "not-in-default-namespace", + Namespace: "other", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, proxy.AppOverview{ - ReleaseName: "not-in-default-namespace", - Namespace: "other", + ReleaseName: "wordpress", + Namespace: "default", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, }, }, @@ -116,8 +123,8 @@ func TestListReleases(t *testing.T) { namespace: "default", listLimit: defaultListLimit, releases: []releaseStub{ - releaseStub{"wordpress", "default", 1}, releaseStub{"airwatch", "default", 1}, + releaseStub{"wordpress", "default", 1}, releaseStub{"not-in-namespace", "other", 1}, }, expectedApps: []proxy.AppOverview{ @@ -125,11 +132,15 @@ func TestListReleases(t *testing.T) { ReleaseName: "airwatch", Namespace: "default", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, proxy.AppOverview{ ReleaseName: "wordpress", Namespace: "default", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, }, }, @@ -138,8 +149,8 @@ func TestListReleases(t *testing.T) { namespace: "default", listLimit: 1, releases: []releaseStub{ - releaseStub{"wordpress", "default", 1}, releaseStub{"airwatch", "default", 1}, + releaseStub{"wordpress", "default", 1}, releaseStub{"not-in-namespace", "other", 1}, }, expectedApps: []proxy.AppOverview{ @@ -147,6 +158,8 @@ func TestListReleases(t *testing.T) { ReleaseName: "airwatch", Namespace: "default", Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, }, }, @@ -161,13 +174,17 @@ func TestListReleases(t *testing.T) { expectedApps: []proxy.AppOverview{ proxy.AppOverview{ ReleaseName: "wordpress", - Namespace: "dev", - Version: "2", + Namespace: "default", + Version: "1", + Status: "deployed", + Icon: "https://example.com/icon.png", }, proxy.AppOverview{ ReleaseName: "wordpress", - Namespace: "default", - Version: "1", + Namespace: "dev", + Version: "2", + Status: "deployed", + Icon: "https://example.com/icon.png", }, }, }, @@ -188,18 +205,9 @@ func TestListReleases(t *testing.T) { t.Errorf("got: %d, want: %d", got, want) } - //Check if expected and returned contain the same releases, given they have same size - m := make(map[releaseStub]bool) - - for _, eapp := range tc.expectedApps { - m[releaseStub{eapp.ReleaseName, eapp.Namespace, strtoi(eapp.Version)}] = true - } - - for _, app := range apps { - rs := releaseStub{app.ReleaseName, app.Namespace, strtoi(app.Version)} - if _, ok := m[rs]; !ok { - t.Errorf("got: %v, want: %v", rs, "None") - } + //Deep equality check of expected aginst attained result + if !cmp.Equal(apps, tc.expectedApps) { + t.Errorf(cmp.Diff(apps, tc.expectedApps)) } })