Skip to content

Commit

Permalink
Deep Equality Check in /pkg/agent test (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
latiif authored and Andres Martinez Gotor committed Dec 18, 2019
1 parent 282b9fb commit 9b7450c
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/client-go/kubernetes"

"github.com/google/go-cmp/cmp"
"github.com/kubeapps/kubeapps/pkg/proxy"
)

Expand Down Expand Up @@ -90,25 +91,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 @@ -117,20 +124,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 @@ -139,15 +150,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 @@ -162,13 +175,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 @@ -189,18 +206,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

0 comments on commit 9b7450c

Please sign in to comment.