Browse code

c8d/TestPsListContainersSize: Only check if size increased

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2023/10/04 21:28:00
Showing 1 changed files
... ...
@@ -186,9 +186,21 @@ func (s *DockerCLIPsSuite) TestPsListContainersSize(c *testing.T) {
186 186
 	idIndex := strings.Index(lines[0], "CONTAINER ID")
187 187
 	foundID := lines[1][idIndex : idIndex+12]
188 188
 	assert.Equal(c, foundID, id[:12], fmt.Sprintf("Expected id %s, got %s", id[:12], foundID))
189
-	expectedSize := units.HumanSize(float64(baseBytes + 2))
190
-	foundSize := lines[1][sizeIndex:]
191
-	assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize)
189
+	foundSize, _, _ := strings.Cut(strings.TrimSpace(lines[1][sizeIndex:]), " ")
190
+
191
+	// With snapshotters the reported usage is the real space occupied on the
192
+	// filesystem (also includes metadata), so this new file can actually
193
+	// result in a bigger increase depending on the underlying filesystem (on
194
+	// ext4 this would be 4096 which is a minimum allocation unit).
195
+	if testEnv.UsingSnapshotter() {
196
+		newBytes, err := units.FromHumanSize(foundSize)
197
+		assert.NilError(c, err)
198
+		// Check if size increased by at least 2 bytes.
199
+		assert.Check(c, newBytes >= baseBytes+2)
200
+	} else {
201
+		expectedSize := units.HumanSize(float64(baseBytes + 2))
202
+		assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize)
203
+	}
192 204
 }
193 205
 
194 206
 func (s *DockerCLIPsSuite) TestPsListContainersFilterStatus(c *testing.T) {