From 8e2d63d5df1a8950ce72307d8d6a0ad80f56ce24 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 28 Mar 2022 20:37:06 +0200 Subject: [PATCH] Fix flaky TestContainerList tests These tests were creating a stub container, using the current timestamp as created date. However, if CI was slow to run the test, `Less than a second ago` would change into `1 second ago`, causing the test to fail: --- FAIL: TestContainerListNoTrunc (0.00s) list_test.go:198: assertion failed: --- expected +++ actual @@ -1,4 +1,4 @@ -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -container_id busybox:latest "top" Less than a second ago Up 1 second c1 -container_id busybox:latest "top" Less than a second ago Up 1 second c2,foo/bar +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +container_id busybox:latest "top" 1 second ago Up 1 second c1 +container_id busybox:latest "top" 1 second ago Up 1 second c2,foo/bar This patch changes the "created" time of the container to be a minute ago. This will result in `About a minute ago`, with a margin of 1 minute. Signed-off-by: Sebastiaan van Stijn --- .../container-list-without-format-no-trunc.golden | 6 +++--- .../testdata/container-list-without-format.golden | 12 ++++++------ internal/test/builders/container.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/command/container/testdata/container-list-without-format-no-trunc.golden b/cli/command/container/testdata/container-list-without-format-no-trunc.golden index b225bc4deb..708676453b 100644 --- a/cli/command/container/testdata/container-list-without-format-no-trunc.golden +++ b/cli/command/container/testdata/container-list-without-format-no-trunc.golden @@ -1,3 +1,3 @@ -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -container_id busybox:latest "top" Less than a second ago Up 1 second c1 -container_id busybox:latest "top" Less than a second ago Up 1 second c2,foo/bar +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +container_id busybox:latest "top" About a minute ago Up 1 minute c1 +container_id busybox:latest "top" About a minute ago Up 1 minute c2,foo/bar diff --git a/cli/command/container/testdata/container-list-without-format.golden b/cli/command/container/testdata/container-list-without-format.golden index af4a92d89e..abd21565ec 100644 --- a/cli/command/container/testdata/container-list-without-format.golden +++ b/cli/command/container/testdata/container-list-without-format.golden @@ -1,6 +1,6 @@ -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -container_id busybox:latest "top" Less than a second ago Up 1 second c1 -container_id busybox:latest "top" Less than a second ago Up 1 second c2 -container_id busybox:latest "top" Less than a second ago Up 1 second 80-82/tcp c3 -container_id busybox:latest "top" Less than a second ago Up 1 second 81/udp c4 -container_id busybox:latest "top" Less than a second ago Up 1 second 8.8.8.8:82->82/tcp c5 +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +container_id busybox:latest "top" About a minute ago Up 1 minute c1 +container_id busybox:latest "top" About a minute ago Up 1 minute c2 +container_id busybox:latest "top" About a minute ago Up 1 minute 80-82/tcp c3 +container_id busybox:latest "top" About a minute ago Up 1 minute 81/udp c4 +container_id busybox:latest "top" About a minute ago Up 1 minute 8.8.8.8:82->82/tcp c5 diff --git a/internal/test/builders/container.go b/internal/test/builders/container.go index 80010554eb..7961f376e8 100644 --- a/internal/test/builders/container.go +++ b/internal/test/builders/container.go @@ -16,8 +16,8 @@ func Container(name string, builders ...func(container *types.Container)) *types Names: []string{"/" + name}, Command: "top", Image: "busybox:latest", - Status: "Up 1 second", - Created: time.Now().Unix(), + Status: "Up 1 minute", + Created: time.Now().Add(-1 * time.Minute).Unix(), } for _, builder := range builders {