From 28d057cb0e7946906c656d82dd6293f8d7e28947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 4 Oct 2023 14:28:00 +0200 Subject: [PATCH] c8d/TestPsListContainersSize: Only check if size increased MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- integration-cli/docker_cli_ps_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index ab0606998c..c8c9744a23 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -186,9 +186,21 @@ func (s *DockerCLIPsSuite) TestPsListContainersSize(c *testing.T) { idIndex := strings.Index(lines[0], "CONTAINER ID") foundID := lines[1][idIndex : idIndex+12] assert.Equal(c, foundID, id[:12], fmt.Sprintf("Expected id %s, got %s", id[:12], foundID)) - expectedSize := units.HumanSize(float64(baseBytes + 2)) - foundSize := lines[1][sizeIndex:] - assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize) + foundSize, _, _ := strings.Cut(strings.TrimSpace(lines[1][sizeIndex:]), " ") + + // With snapshotters the reported usage is the real space occupied on the + // filesystem (also includes metadata), so this new file can actually + // result in a bigger increase depending on the underlying filesystem (on + // ext4 this would be 4096 which is a minimum allocation unit). + if testEnv.UsingSnapshotter() { + newBytes, err := units.FromHumanSize(foundSize) + assert.NilError(c, err) + // Check if size increased by at least 2 bytes. + assert.Check(c, newBytes >= baseBytes+2) + } else { + expectedSize := units.HumanSize(float64(baseBytes + 2)) + assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize) + } } func (s *DockerCLIPsSuite) TestPsListContainersFilterStatus(c *testing.T) {