Skip to content

Commit

Permalink
Merge pull request #4538 from thaJeztah/24.0_backport_history_test
Browse files Browse the repository at this point in the history
[24.0 backport] un-skip history test and fix golden mismatches
  • Loading branch information
thaJeztah authored Aug 29, 2023
2 parents 3789f8a + b83959e commit b74d8e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 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,13 +42,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
}
}

func notUTCTimezone() bool {
now := time.Now()
return now != now.UTC()
}

func TestNewHistoryCommandSuccess(t *testing.T) {
skip.If(t, notUTCTimezone, "expected output requires UTC timezone")
testCases := []struct {
name string
args []string
Expand All @@ -62,6 +55,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
return []image.HistoryResponseItem{{
ID: "1234567890123456789",
Created: time.Now().Unix(),
Comment: "none",
}}, nil
},
},
Expand Down Expand Up @@ -93,13 +87,19 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
},
}
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
cmd := NewHistoryCommand(cli)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NilError(t, err)
actual := cli.OutBuffer().String()
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
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)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NilError(t, err)
actual := cli.OutBuffer().String()
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
})
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
IMAGE CREATED AT CREATED BY SIZE COMMENT
abcdef 2017-01-01T12:00:03Z rose 0 new history item!
IMAGE CREATED AT CREATED BY SIZE COMMENT
abcdef 2017-01-01T12:00:03Z rose 0 new history item!
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
IMAGE CREATED CREATED BY SIZE COMMENT
123456789012 Less than a second ago 0B none

0 comments on commit b74d8e1

Please sign in to comment.