From 0645b92c1b7aff81ed02aeef0faf6ee0bcd070e9 Mon Sep 17 00:00:00 2001 From: Jacob LeGrone Date: Thu, 5 Sep 2019 14:59:10 -0400 Subject: [PATCH] Print test status Signed-off-by: Jacob LeGrone --- cmd/helm/release_testing.go | 9 ++++++++- cmd/helm/status.go | 6 ++++-- cmd/helm/testdata/output/get-release.txt | 1 + cmd/helm/testdata/output/install-and-replace.txt | 1 + cmd/helm/testdata/output/install-name-template.txt | 1 + cmd/helm/testdata/output/install-no-hooks.txt | 1 + .../output/install-with-multiple-values-files.txt | 1 + .../testdata/output/install-with-multiple-values.txt | 1 + cmd/helm/testdata/output/install-with-timeout.txt | 1 + .../testdata/output/install-with-values-file.txt | 1 + cmd/helm/testdata/output/install-with-values.txt | 1 + cmd/helm/testdata/output/install-with-wait.txt | 1 + cmd/helm/testdata/output/install.txt | 1 + cmd/helm/testdata/output/schema.txt | 1 + cmd/helm/testdata/output/status-with-notes.txt | 1 + cmd/helm/testdata/output/status-with-test-suite.txt | 2 -- cmd/helm/testdata/output/status.txt | 1 + cmd/helm/testdata/output/subchart-schema-cli.txt | 1 + .../testdata/output/upgrade-with-install-timeout.txt | 1 + cmd/helm/testdata/output/upgrade-with-install.txt | 1 + .../testdata/output/upgrade-with-reset-values.txt | 1 + .../testdata/output/upgrade-with-reset-values2.txt | 1 + cmd/helm/testdata/output/upgrade-with-timeout.txt | 1 + cmd/helm/testdata/output/upgrade-with-wait.txt | 1 + cmd/helm/testdata/output/upgrade.txt | 1 + pkg/action/release_testing.go | 12 ++++++------ 26 files changed, 40 insertions(+), 11 deletions(-) diff --git a/cmd/helm/release_testing.go b/cmd/helm/release_testing.go index 68f3d0248..a49816305 100644 --- a/cmd/helm/release_testing.go +++ b/cmd/helm/release_testing.go @@ -24,6 +24,7 @@ import ( "helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/cli/output" ) const releaseTestHelp = ` @@ -35,6 +36,7 @@ The tests to be run are defined in the chart that was installed. func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { client := action.NewReleaseTesting(cfg) + var outfmt output.Format cmd := &cobra.Command{ Use: "test [RELEASE]", @@ -42,7 +44,12 @@ func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command Long: releaseTestHelp, Args: require.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return client.Run(args[0]) + rel, err := client.Run(args[0]) + if err != nil { + return err + } + + return outfmt.Write(out, &statusPrinter{rel, settings.Debug}) }, } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index b1475be38..92e12dbe0 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -97,13 +97,15 @@ func (s statusPrinter) WriteTable(out io.Writer) error { fmt.Fprintf(out, "REVISION: %d\n", s.release.Version) executions := executionsByHookEvent(s.release) - if tests, ok := executions[release.HookTest]; ok { + if tests, ok := executions[release.HookTest]; !ok || len(tests) == 0 { + fmt.Fprintln(out, "TEST SUITE: None") + } else { for _, h := range tests { // Don't print anything if hook has not been initiated if h.LastRun.StartedAt.IsZero() { continue } - fmt.Fprintf(out, "TEST SUITE: %s\n%s\n%s\n%s\n\n", + fmt.Fprintf(out, "TEST SUITE: %s\n%s\n%s\n%s\n", h.Name, fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt.Format(time.ANSIC)), fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt.Format(time.ANSIC)), diff --git a/cmd/helm/testdata/output/get-release.txt b/cmd/helm/testdata/output/get-release.txt index e12ed19cd..47b249244 100644 --- a/cmd/helm/testdata/output/get-release.txt +++ b/cmd/helm/testdata/output/get-release.txt @@ -3,6 +3,7 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None USER-SUPPLIED VALUES: name: value diff --git a/cmd/helm/testdata/output/install-and-replace.txt b/cmd/helm/testdata/output/install-and-replace.txt index 0a9aa1803..039d6aef6 100644 --- a/cmd/helm/testdata/output/install-and-replace.txt +++ b/cmd/helm/testdata/output/install-and-replace.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-name-template.txt b/cmd/helm/testdata/output/install-name-template.txt index 70d9b71b9..67e06d92b 100644 --- a/cmd/helm/testdata/output/install-name-template.txt +++ b/cmd/helm/testdata/output/install-name-template.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-no-hooks.txt b/cmd/helm/testdata/output/install-no-hooks.txt index 0a9aa1803..039d6aef6 100644 --- a/cmd/helm/testdata/output/install-no-hooks.txt +++ b/cmd/helm/testdata/output/install-no-hooks.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-multiple-values-files.txt b/cmd/helm/testdata/output/install-with-multiple-values-files.txt index 201e74927..406e522a9 100644 --- a/cmd/helm/testdata/output/install-with-multiple-values-files.txt +++ b/cmd/helm/testdata/output/install-with-multiple-values-files.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-multiple-values.txt b/cmd/helm/testdata/output/install-with-multiple-values.txt index 201e74927..406e522a9 100644 --- a/cmd/helm/testdata/output/install-with-multiple-values.txt +++ b/cmd/helm/testdata/output/install-with-multiple-values.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-timeout.txt b/cmd/helm/testdata/output/install-with-timeout.txt index 9115085db..19952e3c2 100644 --- a/cmd/helm/testdata/output/install-with-timeout.txt +++ b/cmd/helm/testdata/output/install-with-timeout.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-values-file.txt b/cmd/helm/testdata/output/install-with-values-file.txt index 201e74927..406e522a9 100644 --- a/cmd/helm/testdata/output/install-with-values-file.txt +++ b/cmd/helm/testdata/output/install-with-values-file.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-values.txt b/cmd/helm/testdata/output/install-with-values.txt index 201e74927..406e522a9 100644 --- a/cmd/helm/testdata/output/install-with-values.txt +++ b/cmd/helm/testdata/output/install-with-values.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install-with-wait.txt b/cmd/helm/testdata/output/install-with-wait.txt index a5609edb7..7ce22d4ec 100644 --- a/cmd/helm/testdata/output/install-with-wait.txt +++ b/cmd/helm/testdata/output/install-with-wait.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/install.txt b/cmd/helm/testdata/output/install.txt index 0a9aa1803..039d6aef6 100644 --- a/cmd/helm/testdata/output/install.txt +++ b/cmd/helm/testdata/output/install.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/schema.txt b/cmd/helm/testdata/output/schema.txt index 7424e723e..22a94b3f4 100644 --- a/cmd/helm/testdata/output/schema.txt +++ b/cmd/helm/testdata/output/schema.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/status-with-notes.txt b/cmd/helm/testdata/output/status-with-notes.txt index f460b343d..e992ce91e 100644 --- a/cmd/helm/testdata/output/status-with-notes.txt +++ b/cmd/helm/testdata/output/status-with-notes.txt @@ -3,5 +3,6 @@ LAST DEPLOYED: Sat Jan 16 00:00:00 2016 NAMESPACE: default STATUS: deployed REVISION: 0 +TEST SUITE: None NOTES: release notes diff --git a/cmd/helm/testdata/output/status-with-test-suite.txt b/cmd/helm/testdata/output/status-with-test-suite.txt index 79ea4e442..58c67e103 100644 --- a/cmd/helm/testdata/output/status-with-test-suite.txt +++ b/cmd/helm/testdata/output/status-with-test-suite.txt @@ -7,9 +7,7 @@ TEST SUITE: passing-test Last Started: Mon Jan 2 15:04:05 2006 Last Completed: Mon Jan 2 15:04:07 2006 Phase: Succeeded - TEST SUITE: failing-test Last Started: Mon Jan 2 15:10:05 2006 Last Completed: Mon Jan 2 15:10:07 2006 Phase: Failed - diff --git a/cmd/helm/testdata/output/status.txt b/cmd/helm/testdata/output/status.txt index 9d89842db..a326c3db0 100644 --- a/cmd/helm/testdata/output/status.txt +++ b/cmd/helm/testdata/output/status.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Sat Jan 16 00:00:00 2016 NAMESPACE: default STATUS: deployed REVISION: 0 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/subchart-schema-cli.txt b/cmd/helm/testdata/output/subchart-schema-cli.txt index 7424e723e..22a94b3f4 100644 --- a/cmd/helm/testdata/output/subchart-schema-cli.txt +++ b/cmd/helm/testdata/output/subchart-schema-cli.txt @@ -3,3 +3,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-install-timeout.txt b/cmd/helm/testdata/output/upgrade-with-install-timeout.txt index e49fb7dc4..5d8d3a4ea 100644 --- a/cmd/helm/testdata/output/upgrade-with-install-timeout.txt +++ b/cmd/helm/testdata/output/upgrade-with-install-timeout.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 2 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-install.txt b/cmd/helm/testdata/output/upgrade-with-install.txt index bf8b8c403..af61212bd 100644 --- a/cmd/helm/testdata/output/upgrade-with-install.txt +++ b/cmd/helm/testdata/output/upgrade-with-install.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 2 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-reset-values.txt b/cmd/helm/testdata/output/upgrade-with-reset-values.txt index dfb8fec5c..01f1c0ac8 100644 --- a/cmd/helm/testdata/output/upgrade-with-reset-values.txt +++ b/cmd/helm/testdata/output/upgrade-with-reset-values.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 5 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-reset-values2.txt b/cmd/helm/testdata/output/upgrade-with-reset-values2.txt index 34fbe3d07..fdd1d2db7 100644 --- a/cmd/helm/testdata/output/upgrade-with-reset-values2.txt +++ b/cmd/helm/testdata/output/upgrade-with-reset-values2.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 6 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-timeout.txt b/cmd/helm/testdata/output/upgrade-with-timeout.txt index 7b4181f09..be3a42368 100644 --- a/cmd/helm/testdata/output/upgrade-with-timeout.txt +++ b/cmd/helm/testdata/output/upgrade-with-timeout.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 4 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-with-wait.txt b/cmd/helm/testdata/output/upgrade-with-wait.txt index f47ac718d..500d07a11 100644 --- a/cmd/helm/testdata/output/upgrade-with-wait.txt +++ b/cmd/helm/testdata/output/upgrade-with-wait.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 3 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade.txt b/cmd/helm/testdata/output/upgrade.txt index 0f070cce5..bea42db54 100644 --- a/cmd/helm/testdata/output/upgrade.txt +++ b/cmd/helm/testdata/output/upgrade.txt @@ -4,3 +4,4 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 3 +TEST SUITE: None diff --git a/pkg/action/release_testing.go b/pkg/action/release_testing.go index 37d0c3b7f..fbd36bef8 100644 --- a/pkg/action/release_testing.go +++ b/pkg/action/release_testing.go @@ -40,25 +40,25 @@ func NewReleaseTesting(cfg *Configuration) *ReleaseTesting { } // Run executes 'helm test' against the given release. -func (r *ReleaseTesting) Run(name string) error { +func (r *ReleaseTesting) Run(name string) (*release.Release, error) { if err := r.cfg.KubeClient.IsReachable(); err != nil { - return err + return nil, err } if err := validateReleaseName(name); err != nil { - return errors.Errorf("releaseTest: Release name is invalid: %s", name) + return nil, errors.Errorf("releaseTest: Release name is invalid: %s", name) } // finds the non-deleted release with the given name rel, err := r.cfg.Releases.Last(name) if err != nil { - return err + return rel, err } if err := r.cfg.execHook(rel, release.HookTest, r.Timeout); err != nil { r.cfg.Releases.Update(rel) - return err + return rel, err } - return r.cfg.Releases.Update(rel) + return rel, r.cfg.Releases.Update(rel) }