From 90db6b82a36cfd3559864de167ccb4f25af10baa Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 16 Sep 2022 16:29:17 -0400 Subject: [PATCH] cli: use N/A as placeholder for old CREATED dates Signed-off-by: Jason Hall --- cli/command/image/formatter_history.go | 2 +- cli/command/image/formatter_history_test.go | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cli/command/image/formatter_history.go b/cli/command/image/formatter_history.go index 8dabfd852002..4e826cb6412d 100644 --- a/cli/command/image/formatter_history.go +++ b/cli/command/image/formatter_history.go @@ -90,7 +90,7 @@ func (c *historyContext) CreatedSince() string { return c.CreatedAt() } if c.h.Created <= epoch { - return "" + return "N/A" } created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0))) return created + " ago" diff --git a/cli/command/image/formatter_history_test.go b/cli/command/image/formatter_history_test.go index ece557958928..3de08534dd88 100644 --- a/cli/command/image/formatter_history_test.go +++ b/cli/command/image/formatter_history_test.go @@ -12,7 +12,6 @@ import ( "github.com/docker/docker/api/types/image" "github.com/docker/docker/pkg/stringid" "gotest.tools/v3/assert" - "gotest.tools/v3/skip" ) type historyCase struct { @@ -52,8 +51,8 @@ func TestHistoryContext_ID(t *testing.T) { } func TestHistoryContext_CreatedSince(t *testing.T) { - skip.If(t, notUTCTimezone, "expected output requires UTC timezone") - dateStr := "2009-11-10T23:00:00Z" + longerAgo := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + dateStr := longerAgo.Local().Format(time.RFC3339) var ctx historyContext cases := []historyCase{ { @@ -65,7 +64,7 @@ func TestHistoryContext_CreatedSince(t *testing.T) { }, { historyContext{ - h: image.HistoryResponseItem{Created: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()}, + h: image.HistoryResponseItem{Created: longerAgo.Unix()}, trunc: false, human: false, }, dateStr, ctx.CreatedSince, @@ -76,7 +75,7 @@ func TestHistoryContext_CreatedSince(t *testing.T) { h: image.HistoryResponseItem{Created: 0}, trunc: false, human: true, - }, "", ctx.CreatedSince, + }, "N/A", ctx.CreatedSince, }, { // A time before the year 2000 is not displayed. @@ -84,15 +83,15 @@ func TestHistoryContext_CreatedSince(t *testing.T) { h: image.HistoryResponseItem{Created: time.Date(1980, time.November, 10, 10, 23, 0, 0, time.UTC).Unix()}, trunc: false, human: true, - }, "", ctx.CreatedSince, + }, "N/A", ctx.CreatedSince, }, { // A time after 2000 is displayed. historyContext{ - h: image.HistoryResponseItem{Created: time.Date(2005, time.September, 27, 4, 37, 0, 0, time.UTC).Unix()}, + h: image.HistoryResponseItem{Created: time.Now().AddDate(-11, 0, 0).Unix()}, trunc: false, human: true, - }, "", ctx.CreatedSince, + }, "11 years ago", ctx.CreatedSince, }, } @@ -102,7 +101,7 @@ func TestHistoryContext_CreatedSince(t *testing.T) { if strings.Contains(v, ",") { test.CompareMultipleValues(t, v, c.expValue) } else if v != c.expValue { - t.Fatalf("Expected %s, was %s\n", c.expValue, v) + t.Fatalf("Expected %q, was %q\n", c.expValue, v) } } } @@ -219,7 +218,7 @@ imageID1 24 hours ago /bin/bash ls && npm i && npm run test && karma -c karm imageID2 24 hours ago /bin/bash echo 183MB Hi imageID3 24 hours ago /bin/bash ls 183MB Hi imageID4 24 hours ago /bin/bash grep 183MB Hi -imageID5 /bin/bash echo 183MB Hi +imageID5 N/A /bin/bash echo 183MB Hi imageID6 17 years ago /bin/bash echo 183MB Hi ` const expectedTrunc = `IMAGE CREATED CREATED BY SIZE COMMENT @@ -227,7 +226,7 @@ imageID1 24 hours ago /bin/bash ls && npm i && npm run test && kar… 183M imageID2 24 hours ago /bin/bash echo 183MB Hi imageID3 24 hours ago /bin/bash ls 183MB Hi imageID4 24 hours ago /bin/bash grep 183MB Hi -imageID5 /bin/bash echo 183MB Hi +imageID5 N/A /bin/bash echo 183MB Hi imageID6 17 years ago /bin/bash echo 183MB Hi `