From 32712201eca1a3d79a68881396b8983853cd994b Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Wed, 20 Mar 2019 12:56:24 -0700 Subject: [PATCH] ref(list): move namespaces field closer to the name Most users want to see the release name and the namespace it was deployed to, as those are the unique identifiers where the release is stored. I also added integration tests for `helm list` to better test the command output. Signed-off-by: Matthew Fisher --- cmd/helm/list_test.go | 177 ++++++++++++++++++ cmd/helm/testdata/output/list-all.txt | 3 + cmd/helm/testdata/output/list-date.txt | 3 + cmd/helm/testdata/output/list-failed.txt | 2 + cmd/helm/testdata/output/list-filter.txt | 3 + cmd/helm/testdata/output/list-max.txt | 2 + cmd/helm/testdata/output/list-offset.txt | 2 + cmd/helm/testdata/output/list-pending.txt | 2 + cmd/helm/testdata/output/list-reverse.txt | 3 + cmd/helm/testdata/output/list-short.txt | 2 + cmd/helm/testdata/output/list-superseded.txt | 3 + cmd/helm/testdata/output/list-uninstalled.txt | 2 + .../testdata/output/list-uninstalling.txt | 2 + cmd/helm/testdata/output/list.txt | 3 + pkg/action/list.go | 4 +- 15 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 cmd/helm/list_test.go create mode 100644 cmd/helm/testdata/output/list-all.txt create mode 100644 cmd/helm/testdata/output/list-date.txt create mode 100644 cmd/helm/testdata/output/list-failed.txt create mode 100644 cmd/helm/testdata/output/list-filter.txt create mode 100644 cmd/helm/testdata/output/list-max.txt create mode 100644 cmd/helm/testdata/output/list-offset.txt create mode 100644 cmd/helm/testdata/output/list-pending.txt create mode 100644 cmd/helm/testdata/output/list-reverse.txt create mode 100644 cmd/helm/testdata/output/list-short.txt create mode 100644 cmd/helm/testdata/output/list-superseded.txt create mode 100644 cmd/helm/testdata/output/list-uninstalled.txt create mode 100644 cmd/helm/testdata/output/list-uninstalling.txt create mode 100644 cmd/helm/testdata/output/list.txt diff --git a/cmd/helm/list_test.go b/cmd/helm/list_test.go new file mode 100644 index 000000000..08dff52aa --- /dev/null +++ b/cmd/helm/list_test.go @@ -0,0 +1,177 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "testing" + "time" + + "helm.sh/helm/pkg/chart" + "helm.sh/helm/pkg/release" +) + +func TestListCmd(t *testing.T) { + defaultNamespace := "default" + timestamp1 := time.Unix(1452902400, 0).UTC() + timestamp2 := time.Unix(1452902401, 0).UTC() + chartInfo := &chart.Chart{ + Metadata: &chart.Metadata{ + Name: "chickadee", + Version: "1.0.0", + }, + } + releaseFixture := []*release.Release{ + { + Name: "starlord", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp1, + Status: release.StatusSuperseded, + }, + Chart: chartInfo, + }, + { + Name: "starlord", + Version: 2, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp1, + Status: release.StatusDeployed, + }, + Chart: chartInfo, + }, + { + Name: "groot", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp2, + Status: release.StatusUninstalled, + }, + Chart: chartInfo, + }, + { + Name: "gamora", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp1, + Status: release.StatusSuperseded, + }, + Chart: chartInfo, + }, + { + Name: "rocket", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp2, + Status: release.StatusFailed, + }, + Chart: chartInfo, + }, + { + Name: "drax", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp1, + Status: release.StatusUninstalling, + }, + Chart: chartInfo, + }, + { + Name: "thanos", + Version: 1, + Namespace: defaultNamespace, + Info: &release.Info{ + LastDeployed: timestamp1, + Status: release.StatusPendingInstall, + }, + Chart: chartInfo, + }, + } + + tests := []cmdTestCase{{ + name: "list releases", + cmd: "list", + golden: "output/list.txt", + rels: releaseFixture, + }, { + name: "list all releases", + cmd: "list --all", + golden: "output/list-all.txt", + rels: releaseFixture, + }, { + name: "list releases sorted by release date", + cmd: "list --date", + golden: "output/list-date.txt", + rels: releaseFixture, + }, { + name: "list failed releases", + cmd: "list --failed", + golden: "output/list-failed.txt", + rels: releaseFixture, + }, { + name: "list filtered releases", + cmd: "list --filter='.*'", + golden: "output/list-filter.txt", + rels: releaseFixture, + }, { + name: "list releases, limited to one release", + cmd: "list --max 1", + golden: "output/list-max.txt", + rels: releaseFixture, + }, { + name: "list releases, offset by one", + cmd: "list --offset 1", + golden: "output/list-offset.txt", + rels: releaseFixture, + }, { + name: "list pending releases", + cmd: "list --pending", + golden: "output/list-pending.txt", + rels: releaseFixture, + }, { + name: "list releases in reverse order", + cmd: "list --reverse", + golden: "output/list-reverse.txt", + rels: releaseFixture, + }, { + name: "list releases in short output format", + cmd: "list --short", + golden: "output/list-short.txt", + rels: releaseFixture, + }, { + name: "list superseded releases", + cmd: "list --superseded", + golden: "output/list-superseded.txt", + rels: releaseFixture, + }, { + name: "list uninstalled releases", + cmd: "list --uninstalled", + golden: "output/list-uninstalled.txt", + rels: releaseFixture, + }, { + name: "list releases currently uninstalling", + cmd: "list --uninstalling", + golden: "output/list-uninstalling.txt", + rels: releaseFixture, + }} + runTestCmd(t, tests) +} diff --git a/cmd/helm/testdata/output/list-all.txt b/cmd/helm/testdata/output/list-all.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list-all.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-date.txt b/cmd/helm/testdata/output/list-date.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list-date.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-failed.txt b/cmd/helm/testdata/output/list-failed.txt new file mode 100644 index 000000000..f9e56e313 --- /dev/null +++ b/cmd/helm/testdata/output/list-failed.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-filter.txt b/cmd/helm/testdata/output/list-filter.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list-filter.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-max.txt b/cmd/helm/testdata/output/list-max.txt new file mode 100644 index 000000000..8d93a9a09 --- /dev/null +++ b/cmd/helm/testdata/output/list-max.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-offset.txt b/cmd/helm/testdata/output/list-offset.txt new file mode 100644 index 000000000..f9e56e313 --- /dev/null +++ b/cmd/helm/testdata/output/list-offset.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-pending.txt b/cmd/helm/testdata/output/list-pending.txt new file mode 100644 index 000000000..1a03b12dd --- /dev/null +++ b/cmd/helm/testdata/output/list-pending.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +thanos default 1 2016-01-16 00:00:00 +0000 UTC pending-install chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-reverse.txt b/cmd/helm/testdata/output/list-reverse.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list-reverse.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-short.txt b/cmd/helm/testdata/output/list-short.txt new file mode 100644 index 000000000..5f7151e5e --- /dev/null +++ b/cmd/helm/testdata/output/list-short.txt @@ -0,0 +1,2 @@ +starlord +rocket diff --git a/cmd/helm/testdata/output/list-superseded.txt b/cmd/helm/testdata/output/list-superseded.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list-superseded.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-uninstalled.txt b/cmd/helm/testdata/output/list-uninstalled.txt new file mode 100644 index 000000000..f0a419f8e --- /dev/null +++ b/cmd/helm/testdata/output/list-uninstalled.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list-uninstalling.txt b/cmd/helm/testdata/output/list-uninstalling.txt new file mode 100644 index 000000000..99c634c11 --- /dev/null +++ b/cmd/helm/testdata/output/list-uninstalling.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +drax default 1 2016-01-16 00:00:00 +0000 UTC uninstalling chickadee-1.0.0 diff --git a/cmd/helm/testdata/output/list.txt b/cmd/helm/testdata/output/list.txt new file mode 100644 index 000000000..c93262d24 --- /dev/null +++ b/cmd/helm/testdata/output/list.txt @@ -0,0 +1,3 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART +starlord default 2 2016-01-16 00:00:00 +0000 UTC deployed chickadee-1.0.0 +rocket default 1 2016-01-16 00:00:01 +0000 UTC failed chickadee-1.0.0 diff --git a/pkg/action/list.go b/pkg/action/list.go index 3f077af5a..063b4d28e 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -238,7 +238,7 @@ func (l *List) SetStateMask() { func FormatList(rels []*release.Release) string { table := uitable.New() - table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART", "NAMESPACE") + table.AddRow("NAME", "NAMESPACE", "REVISION", "UPDATED", "STATUS", "CHART") for _, r := range rels { md := r.Chart.Metadata c := fmt.Sprintf("%s-%s", md.Name, md.Version) @@ -249,7 +249,7 @@ func FormatList(rels []*release.Release) string { s := r.Info.Status.String() v := r.Version n := r.Namespace - table.AddRow(r.Name, v, t, s, c, n) + table.AddRow(r.Name, n, v, t, s, c) } return table.String() }