Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep Equality Check in /pkg/agent test #1379

Merged
merged 9 commits into from
Dec 18, 2019
54 changes: 31 additions & 23 deletions pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -89,25 +90,31 @@ 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{
proxy.AppOverview{
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",
},
},
},
Expand All @@ -116,20 +123,24 @@ 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{
proxy.AppOverview{
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",
},
},
},
Expand All @@ -138,15 +149,17 @@ 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{
proxy.AppOverview{
ReleaseName: "airwatch",
Namespace: "default",
Version: "1",
Status: "deployed",
Icon: "https://example.com/icon.png",
},
},
},
Expand All @@ -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",
},
},
},
Expand All @@ -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))
}

})
Expand Down