Skip to content

Commit

Permalink
force TestNewHistoryCommandSuccess to use UTC timezone
Browse files Browse the repository at this point in the history
This test was skipped if the host was not using UTC timezone, because the output
of timestamps would be different, causing the test to fail.

This patch overrides the TZ env-var to make the test use UTC, so that we don't
have to skip the test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 42ac5d4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Aug 28, 2023
1 parent 28a08a2 commit b83959e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions cli/command/image/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/pkg/errors"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
"gotest.tools/v3/skip"
)

func TestNewHistoryCommandErrors(t *testing.T) {
Expand Down Expand Up @@ -43,16 +42,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
}
}

func notUTCTimezone() bool {
if _, offset := time.Now().Zone(); offset != 0 {
return true
}
return false
}

func TestNewHistoryCommandSuccess(t *testing.T) {
skip.If(t, notUTCTimezone, "expected output requires UTC timezone")

testCases := []struct {
name string
args []string
Expand All @@ -65,6 +55,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
return []image.HistoryResponseItem{{
ID: "1234567890123456789",
Created: time.Now().Unix(),
Comment: "none",
}}, nil
},
},
Expand Down Expand Up @@ -98,6 +89,9 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// Set to UTC timezone as timestamps in output are
// printed in the current timezone
t.Setenv("TZ", "UTC")
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
cmd := NewHistoryCommand(cli)
cmd.SetOut(io.Discard)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
IMAGE CREATED CREATED BY SIZE COMMENT
123456789012 Less than a second ago 0B
123456789012 Less than a second ago 0B none

0 comments on commit b83959e

Please sign in to comment.