This fix migrates docker rm test in integration-cli
to api tests.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,32 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "github.com/docker/docker/integration-cli/checker" |
|
| 5 |
- "github.com/docker/docker/integration-cli/cli/build" |
|
| 6 |
- "github.com/go-check/check" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
|
| 10 |
- dockerfile1 := `FROM busybox:latest |
|
| 11 |
- ENTRYPOINT ["true"]` |
|
| 12 |
- img := "test-container-orphaning" |
|
| 13 |
- dockerfile2 := `FROM busybox:latest |
|
| 14 |
- ENTRYPOINT ["true"] |
|
| 15 |
- MAINTAINER Integration Tests` |
|
| 16 |
- |
|
| 17 |
- // build first dockerfile |
|
| 18 |
- buildImageSuccessfully(c, img, build.WithDockerfile(dockerfile1)) |
|
| 19 |
- img1 := getIDByName(c, img) |
|
| 20 |
- // run container on first image |
|
| 21 |
- dockerCmd(c, "run", img) |
|
| 22 |
- // rebuild dockerfile with a small addition at the end |
|
| 23 |
- buildImageSuccessfully(c, img, build.WithDockerfile(dockerfile2)) |
|
| 24 |
- // try to remove the image, should not error out. |
|
| 25 |
- out, _, err := dockerCmdWithError("rmi", img)
|
|
| 26 |
- c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out))
|
|
| 27 |
- |
|
| 28 |
- // check if we deleted the first image |
|
| 29 |
- out, _ = dockerCmd(c, "images", "-q", "--no-trunc") |
|
| 30 |
- c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
|
|
| 31 |
- |
|
| 32 |
-} |
| 33 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,60 @@ |
| 0 |
+package image // import "github.com/docker/docker/integration/image" |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ "testing" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/docker/docker/api/types" |
|
| 7 |
+ "github.com/docker/docker/integration/internal/container" |
|
| 8 |
+ "github.com/docker/docker/integration/internal/request" |
|
| 9 |
+ "github.com/docker/docker/internal/testutil" |
|
| 10 |
+ "github.com/stretchr/testify/assert" |
|
| 11 |
+ "github.com/stretchr/testify/require" |
|
| 12 |
+) |
|
| 13 |
+ |
|
| 14 |
+func TestRemoveImageOrphaning(t *testing.T) {
|
|
| 15 |
+ defer setupTest(t)() |
|
| 16 |
+ ctx := context.Background() |
|
| 17 |
+ client := request.NewAPIClient(t) |
|
| 18 |
+ |
|
| 19 |
+ img := "test-container-orphaning" |
|
| 20 |
+ |
|
| 21 |
+ // Create a container from busybox, and commit a small change so we have a new image |
|
| 22 |
+ cID1 := container.Create(t, ctx, client, container.WithCmd(""))
|
|
| 23 |
+ commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
|
| 24 |
+ Changes: []string{`ENTRYPOINT ["true"]`},
|
|
| 25 |
+ Reference: img, |
|
| 26 |
+ }) |
|
| 27 |
+ require.NoError(t, err) |
|
| 28 |
+ |
|
| 29 |
+ // verifies that reference now points to first image |
|
| 30 |
+ resp, _, err := client.ImageInspectWithRaw(ctx, img) |
|
| 31 |
+ require.NoError(t, err) |
|
| 32 |
+ assert.Equal(t, resp.ID, commitResp1.ID) |
|
| 33 |
+ |
|
| 34 |
+ // Create a container from created image, and commit a small change with same reference name |
|
| 35 |
+ cID2 := container.Create(t, ctx, client, container.WithImage(img), container.WithCmd(""))
|
|
| 36 |
+ commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
|
| 37 |
+ Changes: []string{`LABEL Maintainer="Integration Tests"`},
|
|
| 38 |
+ Reference: img, |
|
| 39 |
+ }) |
|
| 40 |
+ require.NoError(t, err) |
|
| 41 |
+ |
|
| 42 |
+ // verifies that reference now points to second image |
|
| 43 |
+ resp, _, err = client.ImageInspectWithRaw(ctx, img) |
|
| 44 |
+ require.NoError(t, err) |
|
| 45 |
+ assert.Equal(t, resp.ID, commitResp2.ID) |
|
| 46 |
+ |
|
| 47 |
+ // try to remove the image, should not error out. |
|
| 48 |
+ _, err = client.ImageRemove(ctx, img, types.ImageRemoveOptions{})
|
|
| 49 |
+ require.NoError(t, err) |
|
| 50 |
+ |
|
| 51 |
+ // check if the first image is still there |
|
| 52 |
+ resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID) |
|
| 53 |
+ require.NoError(t, err) |
|
| 54 |
+ assert.Equal(t, resp.ID, commitResp1.ID) |
|
| 55 |
+ |
|
| 56 |
+ // check if the second image has been deleted |
|
| 57 |
+ _, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID) |
|
| 58 |
+ testutil.ErrorContains(t, err, "No such image:") |
|
| 59 |
+} |