Browse code

integration/prune: Run in a separate daemon

Isolate the prune effects by running the test in a separate daemon.
This minimizes the impact of/on other integration tests.

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

Paweł Gronowski authored on 2023/12/05 20:58:22
Showing 1 changed files
... ...
@@ -1,31 +1,49 @@
1 1
 package image
2 2
 
3 3
 import (
4
+	"strings"
4 5
 	"testing"
5 6
 
6 7
 	"github.com/docker/docker/api/types/filters"
7 8
 	"github.com/docker/docker/integration/internal/container"
8 9
 	"github.com/docker/docker/internal/testutils/specialimage"
10
+	"github.com/docker/docker/testutil/daemon"
9 11
 	"gotest.tools/v3/assert"
10
-	is "gotest.tools/v3/assert/cmp"
11 12
 	"gotest.tools/v3/skip"
12 13
 )
13 14
 
14 15
 // Regression test for: https://github.com/moby/moby/issues/45732
15 16
 func TestPruneDontDeleteUsedDangling(t *testing.T) {
16
-	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: hack/make/.build-empty-images doesn't run on Windows")
17
+	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "cannot start multiple daemons on windows")
18
+	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
17 19
 
18 20
 	ctx := setupTest(t)
19
-	client := testEnv.APIClient()
21
+
22
+	d := daemon.New(t)
23
+	d.Start(t)
24
+	defer d.Stop(t)
25
+
26
+	client := d.NewClientT(t)
27
+	defer client.Close()
20 28
 
21 29
 	danglingID := specialimage.Load(ctx, t, client, specialimage.Dangling)
22 30
 
31
+	_, _, err := client.ImageInspectWithRaw(ctx, danglingID)
32
+	assert.NilError(t, err, "Test dangling image doesn't exist")
33
+
23 34
 	container.Create(ctx, t, client,
24 35
 		container.WithImage(danglingID),
25 36
 		container.WithCmd("sleep", "60"))
26 37
 
27 38
 	pruned, err := client.ImagesPrune(ctx, filters.NewArgs(filters.Arg("dangling", "true")))
28
-
29 39
 	assert.NilError(t, err)
30
-	assert.Check(t, is.Len(pruned.ImagesDeleted, 0))
40
+
41
+	for _, deleted := range pruned.ImagesDeleted {
42
+		if strings.Contains(deleted.Deleted, danglingID) || strings.Contains(deleted.Untagged, danglingID) {
43
+			t.Errorf("used dangling image %s shouldn't be deleted", danglingID)
44
+		}
45
+	}
46
+
47
+	_, _, err = client.ImageInspectWithRaw(ctx, danglingID)
48
+	assert.NilError(t, err, "Test dangling image should still exist")
31 49
 }