Display local times in 'helm status' table output

Signed-off-by: Reinaldo de Souza Jr <github@rei.nal.do>
pull/9187/head
Reinaldo de Souza Jr 5 years ago
parent bd13ad3052
commit 7d31d35770

@ -18,6 +18,7 @@ package main
import ( import (
"testing" "testing"
"time"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
) )
@ -39,7 +40,11 @@ func TestGetCmd(t *testing.T) {
golden: "output/get-all-no-args.txt", golden: "output/get-all-no-args.txt",
wantError: true, wantError: true,
}} }}
prevLocal := time.Local
time.Local = time.UTC
runTestCmd(t, tests) runTestCmd(t, tests)
time.Local = prevLocal
} }
func TestGetAllRevisionCompletion(t *testing.T) { func TestGetAllRevisionCompletion(t *testing.T) {

@ -19,6 +19,7 @@ package main
import ( import (
"fmt" "fmt"
"testing" "testing"
"time"
) )
func TestInstall(t *testing.T) { func TestInstall(t *testing.T) {
@ -209,7 +210,10 @@ func TestInstall(t *testing.T) {
}, },
} }
prevLocal := time.Local
time.Local = time.UTC
runTestActionCmd(t, tests) runTestActionCmd(t, tests)
time.Local = prevLocal
} }
func TestInstallOutputCompletion(t *testing.T) { func TestInstallOutputCompletion(t *testing.T) {

@ -115,7 +115,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error {
} }
fmt.Fprintf(out, "NAME: %s\n", s.release.Name) fmt.Fprintf(out, "NAME: %s\n", s.release.Name)
if !s.release.Info.LastDeployed.IsZero() { 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, "NAMESPACE: %s\n", s.release.Namespace)
fmt.Fprintf(out, "STATUS: %s\n", s.release.Info.Status.String()) 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", fmt.Fprintf(out, "TEST SUITE: %s\n%s\n%s\n%s\n",
h.Name, h.Name,
fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt.Format(time.ANSIC)), fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt.Local().Format(time.ANSIC)),
fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt.Format(time.ANSIC)), fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt.Local().Format(time.ANSIC)),
fmt.Sprintf("Phase: %s", h.LastRun.Phase), fmt.Sprintf("Phase: %s", h.LastRun.Phase),
) )
} }

@ -109,7 +109,61 @@ func TestStatusCmd(t *testing.T) {
}, },
), ),
}} }}
prevLocal := time.Local
time.Local = time.UTC
runTestCmd(t, tests) 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 { func mustParseTime(t string) helmtime.Time {

@ -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

@ -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

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"time"
"helm.sh/helm/v3/internal/test/ensure" "helm.sh/helm/v3/internal/test/ensure"
"helm.sh/helm/v3/pkg/chart" "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)}, rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, release.StatusPendingInstall)},
}, },
} }
prevLocal := time.Local
time.Local = time.UTC
runTestCmd(t, tests) runTestCmd(t, tests)
time.Local = prevLocal
} }
func TestUpgradeWithValue(t *testing.T) { func TestUpgradeWithValue(t *testing.T) {

Loading…
Cancel
Save