From ab5209a9e75248b8c6259b504ee45a0777988c93 Mon Sep 17 00:00:00 2001 From: Mujib Ahasan Date: Wed, 15 Jul 2026 23:58:50 +0530 Subject: [PATCH] test case added Signed-off-by: Mujib Ahasan --- pkg/cmd/history.go | 2 +- pkg/cmd/history_test.go | 89 +++++++++++++++++++ .../output/history-timezone-with-rollback.txt | 4 + pkg/cmd/testdata/output/history-timezone.txt | 4 + 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 pkg/cmd/testdata/output/history-timezone-with-rollback.txt create mode 100644 pkg/cmd/testdata/output/history-timezone.txt diff --git a/pkg/cmd/history.go b/pkg/cmd/history.go index 31d7a8736..16cec1b12 100644 --- a/pkg/cmd/history.go +++ b/pkg/cmd/history.go @@ -218,7 +218,7 @@ func (r releaseHistoryWithRollback) WriteTable(out io.Writer) error { if item.RollbackRevision > 0 { rollback = strconv.Itoa(item.RollbackRevision) } - tbl.AddRow(item.Revision, item.Updated.Format(time.ANSIC), item.Status, item.Chart, item.AppVersion, rollback, item.Description) + tbl.AddRow(item.Revision, item.Updated.In(time.Local).Format(time.ANSIC), item.Status, item.Chart, item.AppVersion, rollback, item.Description) } return output.EncodeTable(out, tbl) } diff --git a/pkg/cmd/history_test.go b/pkg/cmd/history_test.go index 2bace98e0..69af197a2 100644 --- a/pkg/cmd/history_test.go +++ b/pkg/cmd/history_test.go @@ -26,6 +26,8 @@ import ( "github.com/stretchr/testify/require" chart "helm.sh/helm/v4/pkg/chart/v2" + + "helm.sh/helm/v4/internal/test" "helm.sh/helm/v4/pkg/release/common" release "helm.sh/helm/v4/pkg/release/v1" ) @@ -148,6 +150,93 @@ func TestHistoryWithRollback(t *testing.T) { runTestCmd(t, tests) } +func TestHistoryCmdRespectsTimezone(t *testing.T) { + location := time.FixedZone("UTC-4", -4*60*60) + + prevLocal := time.Local + time.Local = location + t.Cleanup(func() { + time.Local = prevLocal + }) + + date := time.Unix(242085845, 0).UTC() + ch := &chart.Chart{ + Metadata: &chart.Metadata{ + Name: "foo", + Version: "0.1.0-beta.1", + AppVersion: "1.0", + }, + } + + releases := []*release.Release{ + { + Name: "angry-bird", + Version: 1, + Info: &release.Info{ + FirstDeployed: date, + LastDeployed: date, + Status: common.StatusSuperseded, + Description: "Install complete", + }, + Chart: ch, + }, + { + Name: "angry-bird", + Version: 2, + Info: &release.Info{ + FirstDeployed: date, + LastDeployed: date, + Status: common.StatusSuperseded, + Description: "Upgrade complete", + }, + Chart: ch, + }, + { + Name: "angry-bird", + Version: 3, + Info: &release.Info{ + FirstDeployed: date, + LastDeployed: date, + Status: common.StatusDeployed, + RollbackRevision: 1, + Description: "Rollback to 1", + }, + Chart: ch, + }, + } + + tests := []struct { + name string + command string + golden string + }{ + { + name: "default table", + command: "history angry-bird", + golden: "output/history-timezone.txt", + }, + { + name: "rollback revision table", + command: "history angry-bird --show-rollback-revision", + golden: "output/history-timezone-with-rollback.txt", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + storage := storageFixture() + for _, rel := range releases { + require.NoError(t, storage.Create(rel)) + } + + _, out, err := executeActionCommandC(storage, tt.command) + require.NoError(t, err) + + test.AssertGoldenString(t, out, tt.golden) + }) + } +} + func TestHistoryOutputCompletion(t *testing.T) { outputFlagCompletionTest(t, "history") } diff --git a/pkg/cmd/testdata/output/history-timezone-with-rollback.txt b/pkg/cmd/testdata/output/history-timezone-with-rollback.txt new file mode 100644 index 000000000..84096ca64 --- /dev/null +++ b/pkg/cmd/testdata/output/history-timezone-with-rollback.txt @@ -0,0 +1,4 @@ +REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION +1 Fri Sep 2 18:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Install complete +2 Fri Sep 2 18:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Upgrade complete +3 Fri Sep 2 18:04:05 1977 deployed foo-0.1.0-beta.1 1.0 1 Rollback to 1 diff --git a/pkg/cmd/testdata/output/history-timezone.txt b/pkg/cmd/testdata/output/history-timezone.txt new file mode 100644 index 000000000..5053f28ec --- /dev/null +++ b/pkg/cmd/testdata/output/history-timezone.txt @@ -0,0 +1,4 @@ +REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION +1 Fri Sep 2 18:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Install complete +2 Fri Sep 2 18:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Upgrade complete +3 Fri Sep 2 18:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Rollback to 1