diff --git a/cmd/helm/get_all_test.go b/cmd/helm/get_all_test.go index 0c140faf8..b98d71b6f 100644 --- a/cmd/helm/get_all_test.go +++ b/cmd/helm/get_all_test.go @@ -18,6 +18,7 @@ package main import ( "testing" + "time" "helm.sh/helm/v3/pkg/release" ) @@ -39,7 +40,11 @@ func TestGetCmd(t *testing.T) { golden: "output/get-all-no-args.txt", wantError: true, }} + + prevLocal := time.Local + time.Local = time.UTC runTestCmd(t, tests) + time.Local = prevLocal } func TestGetAllRevisionCompletion(t *testing.T) { diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 0fae79534..e2ca87b5e 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -19,6 +19,7 @@ package main import ( "fmt" "testing" + "time" ) func TestInstall(t *testing.T) { @@ -209,7 +210,10 @@ func TestInstall(t *testing.T) { }, } + prevLocal := time.Local + time.Local = time.UTC runTestActionCmd(t, tests) + time.Local = prevLocal } func TestInstallOutputCompletion(t *testing.T) { diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 7a3204cb9..14e9a3619 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -115,7 +115,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error { } fmt.Fprintf(out, "NAME: %s\n", s.release.Name) if !s.release.Info.LastDeployed.IsZero() { - fmt.Fprintf(out, "LAST DEPLOYED: %s\n", s.release.Info.LastDeployed.Format(time.ANSIC)) + fmt.Fprintf(out, "LAST DEPLOYED: %s\n", s.release.Info.LastDeployed.Local().Format(time.ANSIC)) } fmt.Fprintf(out, "NAMESPACE: %s\n", s.release.Namespace) fmt.Fprintf(out, "STATUS: %s\n", s.release.Info.Status.String()) @@ -135,8 +135,8 @@ func (s statusPrinter) WriteTable(out io.Writer) error { } 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)), + fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt.Local().Format(time.ANSIC)), + fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt.Local().Format(time.ANSIC)), fmt.Sprintf("Phase: %s", h.LastRun.Phase), ) } diff --git a/cmd/helm/status_test.go b/cmd/helm/status_test.go index 280f486a3..1ee5457d5 100644 --- a/cmd/helm/status_test.go +++ b/cmd/helm/status_test.go @@ -109,7 +109,61 @@ func TestStatusCmd(t *testing.T) { }, ), }} + + prevLocal := time.Local + time.Local = time.UTC runTestCmd(t, tests) + + time.Local = time.FixedZone("Arbitrary", 5*60*60) + runTestCmd(t, []cmdTestCase{{ + name: "get status of a deployed release", + cmd: "status flummoxed-chickadee", + golden: "output/status-utc+5.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + }), + }, { + name: "get status of a deployed release with test suite", + cmd: "status flummoxed-chickadee", + golden: "output/status-with-test-suite-utc+5.txt", + rels: releasesMockWithStatus( + &release.Info{ + Status: release.StatusDeployed, + }, + &release.Hook{ + Name: "never-run-test", + Events: []release.HookEvent{release.HookTest}, + }, + &release.Hook{ + Name: "passing-test", + Events: []release.HookEvent{release.HookTest}, + LastRun: release.HookExecution{ + StartedAt: mustParseTime("2006-01-02T15:04:05Z"), + CompletedAt: mustParseTime("2006-01-02T15:04:07Z"), + Phase: release.HookPhaseSucceeded, + }, + }, + &release.Hook{ + Name: "failing-test", + Events: []release.HookEvent{release.HookTest}, + LastRun: release.HookExecution{ + StartedAt: mustParseTime("2006-01-02T15:10:05Z"), + CompletedAt: mustParseTime("2006-01-02T15:10:07Z"), + Phase: release.HookPhaseFailed, + }, + }, + &release.Hook{ + Name: "passing-pre-install", + Events: []release.HookEvent{release.HookPreInstall}, + LastRun: release.HookExecution{ + StartedAt: mustParseTime("2006-01-02T15:00:05Z"), + CompletedAt: mustParseTime("2006-01-02T15:00:07Z"), + Phase: release.HookPhaseSucceeded, + }, + }, + ), + }}) + time.Local = prevLocal } func mustParseTime(t string) helmtime.Time { diff --git a/cmd/helm/testdata/output/status-utc+5.txt b/cmd/helm/testdata/output/status-utc+5.txt new file mode 100644 index 000000000..acf20a0dd --- /dev/null +++ b/cmd/helm/testdata/output/status-utc+5.txt @@ -0,0 +1,6 @@ +NAME: flummoxed-chickadee +LAST DEPLOYED: Sat Jan 16 05:00:00 2016 +NAMESPACE: default +STATUS: deployed +REVISION: 0 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/status-with-test-suite-utc+5.txt b/cmd/helm/testdata/output/status-with-test-suite-utc+5.txt new file mode 100644 index 000000000..b4212bc5a --- /dev/null +++ b/cmd/helm/testdata/output/status-with-test-suite-utc+5.txt @@ -0,0 +1,13 @@ +NAME: flummoxed-chickadee +LAST DEPLOYED: Sat Jan 16 05:00:00 2016 +NAMESPACE: default +STATUS: deployed +REVISION: 0 +TEST SUITE: passing-test +Last Started: Mon Jan 2 20:04:05 2006 +Last Completed: Mon Jan 2 20:04:07 2006 +Phase: Succeeded +TEST SUITE: failing-test +Last Started: Mon Jan 2 20:10:05 2006 +Last Completed: Mon Jan 2 20:10:07 2006 +Phase: Failed diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index e952a5933..e6b602a7b 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" "testing" + "time" "helm.sh/helm/v3/internal/test/ensure" "helm.sh/helm/v3/pkg/chart" @@ -169,7 +170,11 @@ func TestUpgradeCmd(t *testing.T) { rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, release.StatusPendingInstall)}, }, } + + prevLocal := time.Local + time.Local = time.UTC runTestCmd(t, tests) + time.Local = prevLocal } func TestUpgradeWithValue(t *testing.T) {