un-skip history test and fix golden mismatches

Signed-off-by: Jason Hall <jason@chainguard.dev>
(cherry picked from commit f5e224e940)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Jason Hall 2022-09-19 10:04:53 -04:00 committed by Sebastiaan van Stijn
parent cdd81d6559
commit 28a08a22b9
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 20 additions and 14 deletions

View File

@ -44,12 +44,15 @@ func TestNewHistoryCommandErrors(t *testing.T) {
} }
func notUTCTimezone() bool { func notUTCTimezone() bool {
now := time.Now() if _, offset := time.Now().Zone(); offset != 0 {
return now != now.UTC() return true
}
return false
} }
func TestNewHistoryCommandSuccess(t *testing.T) { func TestNewHistoryCommandSuccess(t *testing.T) {
skip.If(t, notUTCTimezone, "expected output requires UTC timezone") skip.If(t, notUTCTimezone, "expected output requires UTC timezone")
testCases := []struct { testCases := []struct {
name string name string
args []string args []string
@ -93,13 +96,16 @@ 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) cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
cmd.SetArgs(tc.args) cmd := NewHistoryCommand(cli)
err := cmd.Execute() cmd.SetOut(io.Discard)
assert.NilError(t, err) cmd.SetArgs(tc.args)
actual := cli.OutBuffer().String() err := cmd.Execute()
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) 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