Skip to content

Commit

Permalink
List all statuses if required (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Jan 10, 2020
1 parent 54e0afc commit a371f7a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
3 changes: 3 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func ListReleases(actionConfig *action.Configuration, namespace string, listLimi
cmd.AllNamespaces = true
}
cmd.Limit = listLimit
if status == "all" {
cmd.StateMask = action.ListAll
}
releases, err := cmd.Run()
if err != nil {
return nil, err
Expand Down
78 changes: 62 additions & 16 deletions pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type releaseStub struct {
name string
namespace string
version int
status release.Status
}

// makeReleases adds a slice of releases to the configured storage.
Expand All @@ -60,7 +61,7 @@ func makeReleases(t *testing.T, config *Config, rels []releaseStub) {
Namespace: r.namespace,
Version: r.version,
Info: &release.Info{
Status: release.StatusDeployed,
Status: r.status,
},
Chart: &chart.Chart{
Metadata: &chart.Metadata{
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestCreateReleases(t *testing.T) {
namespace: "default",
version: 1,
existingReleases: []releaseStub{
releaseStub{"otherchart", "default", 1},
releaseStub{"otherchart", "default", 1, release.StatusDeployed},
},
shouldFail: false,
},
Expand All @@ -104,7 +105,7 @@ func TestCreateReleases(t *testing.T) {
namespace: "default",
version: 1,
existingReleases: []releaseStub{
releaseStub{"mychart", "default", 1},
releaseStub{"mychart", "default", 1, release.StatusDeployed},
},
shouldFail: true,
},
Expand All @@ -115,7 +116,7 @@ func TestCreateReleases(t *testing.T) {
namespace: "dev",
version: 1,
existingReleases: []releaseStub{
releaseStub{"mychart", "dev", 2},
releaseStub{"mychart", "dev", 2, release.StatusDeployed},
},
shouldFail: true,
},
Expand Down Expand Up @@ -148,6 +149,7 @@ func TestListReleases(t *testing.T) {
name string
namespace string
listLimit int
status string
releases []releaseStub
expectedApps []proxy.AppOverview
}{
Expand All @@ -156,9 +158,9 @@ func TestListReleases(t *testing.T) {
namespace: "",
listLimit: defaultListLimit,
releases: []releaseStub{
releaseStub{"airwatch", "default", 1},
releaseStub{"wordpress", "default", 1},
releaseStub{"not-in-default-namespace", "other", 1},
releaseStub{"airwatch", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"not-in-default-namespace", "other", 1, release.StatusDeployed},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
Expand Down Expand Up @@ -189,9 +191,9 @@ func TestListReleases(t *testing.T) {
namespace: "default",
listLimit: defaultListLimit,
releases: []releaseStub{
releaseStub{"airwatch", "default", 1},
releaseStub{"wordpress", "default", 1},
releaseStub{"not-in-namespace", "other", 1},
releaseStub{"airwatch", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"not-in-namespace", "other", 1, release.StatusDeployed},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
Expand All @@ -215,9 +217,9 @@ func TestListReleases(t *testing.T) {
namespace: "default",
listLimit: 1,
releases: []releaseStub{
releaseStub{"airwatch", "default", 1},
releaseStub{"wordpress", "default", 1},
releaseStub{"not-in-namespace", "other", 1},
releaseStub{"airwatch", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"not-in-namespace", "other", 1, release.StatusDeployed},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
Expand All @@ -234,8 +236,8 @@ func TestListReleases(t *testing.T) {
namespace: "",
listLimit: defaultListLimit,
releases: []releaseStub{
releaseStub{"wordpress", "default", 1},
releaseStub{"wordpress", "dev", 2},
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "dev", 2, release.StatusDeployed},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
Expand All @@ -254,14 +256,58 @@ func TestListReleases(t *testing.T) {
},
},
},
{
name: "ignore uninstalled apps",
namespace: "",
listLimit: defaultListLimit,
releases: []releaseStub{
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "dev", 2, release.StatusUninstalled},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
ReleaseName: "wordpress",
Namespace: "default",
Version: "1",
Status: "deployed",
Icon: "https://example.com/icon.png",
},
},
},
{
name: "include uninstalled apps when requesting all statuses",
namespace: "",
status: "all",
listLimit: defaultListLimit,
releases: []releaseStub{
releaseStub{"wordpress", "default", 1, release.StatusDeployed},
releaseStub{"wordpress", "dev", 2, release.StatusUninstalled},
},
expectedApps: []proxy.AppOverview{
proxy.AppOverview{
ReleaseName: "wordpress",
Namespace: "default",
Version: "1",
Status: "deployed",
Icon: "https://example.com/icon.png",
},
proxy.AppOverview{
ReleaseName: "wordpress",
Namespace: "dev",
Version: "2",
Status: "uninstalled",
Icon: "https://example.com/icon.png",
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
config := newConfigFixture(t)
makeReleases(t, config, tc.releases)

apps, err := ListReleases(config.ActionConfig, tc.namespace, tc.listLimit, "ignored?")
apps, err := ListReleases(config.ActionConfig, tc.namespace, tc.listLimit, tc.status)
if err != nil {
t.Errorf("%v", err)
}
Expand Down

0 comments on commit a371f7a

Please sign in to comment.