Merge pull request #4538 from thaJeztah/24.0_backport_history_test

[24.0 backport] un-skip history test and fix golden mismatches
This commit is contained in:
Sebastiaan van Stijn 2023-08-29 11:43:55 +02:00 committed by GitHub
commit b74d8e1a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
"gotest.tools/v3/skip"
) )
func TestNewHistoryCommandErrors(t *testing.T) { func TestNewHistoryCommandErrors(t *testing.T) {
@ -43,13 +42,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
} }
} }
func notUTCTimezone() bool {
now := time.Now()
return now != now.UTC()
}
func TestNewHistoryCommandSuccess(t *testing.T) { func TestNewHistoryCommandSuccess(t *testing.T) {
skip.If(t, notUTCTimezone, "expected output requires UTC timezone")
testCases := []struct { testCases := []struct {
name string name string
args []string args []string
@ -62,6 +55,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
return []image.HistoryResponseItem{{ return []image.HistoryResponseItem{{
ID: "1234567890123456789", ID: "1234567890123456789",
Created: time.Now().Unix(), Created: time.Now().Unix(),
Comment: "none",
}}, nil }}, nil
}, },
}, },
@ -93,13 +87,19 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}) tc := tc
cmd := NewHistoryCommand(cli) t.Run(tc.name, func(t *testing.T) {
cmd.SetOut(io.Discard) // Set to UTC timezone as timestamps in output are
cmd.SetArgs(tc.args) // printed in the current timezone
err := cmd.Execute() t.Setenv("TZ", "UTC")
assert.NilError(t, err) cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
actual := cli.OutBuffer().String() cmd := NewHistoryCommand(cli)
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) 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))
})
} }
} }

View File

@ -1,2 +1,2 @@
IMAGE CREATED AT CREATED BY SIZE COMMENT IMAGE CREATED AT CREATED BY SIZE COMMENT
abcdef 2017-01-01T12:00:03Z rose 0 new history item! abcdef 2017-01-01T12:00:03Z rose 0 new history item!

View File

@ -1,2 +1,2 @@
IMAGE CREATED CREATED BY SIZE COMMENT IMAGE CREATED CREATED BY SIZE COMMENT
123456789012 Less than a second ago 0B 123456789012 Less than a second ago 0B none