mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Migrate docker rm tests to api tests
This fix migrates docker rm test in integration-cli to api tests. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
4b2fb7e394
commit
ed58ba99fb
2 changed files with 60 additions and 32 deletions
|
@ -1,32 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
||||
dockerfile1 := `FROM busybox:latest
|
||||
ENTRYPOINT ["true"]`
|
||||
img := "test-container-orphaning"
|
||||
dockerfile2 := `FROM busybox:latest
|
||||
ENTRYPOINT ["true"]
|
||||
MAINTAINER Integration Tests`
|
||||
|
||||
// build first dockerfile
|
||||
buildImageSuccessfully(c, img, build.WithDockerfile(dockerfile1))
|
||||
img1 := getIDByName(c, img)
|
||||
// run container on first image
|
||||
dockerCmd(c, "run", img)
|
||||
// rebuild dockerfile with a small addition at the end
|
||||
buildImageSuccessfully(c, img, build.WithDockerfile(dockerfile2))
|
||||
// try to remove the image, should not error out.
|
||||
out, _, err := dockerCmdWithError("rmi", img)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out))
|
||||
|
||||
// check if we deleted the first image
|
||||
out, _ = dockerCmd(c, "images", "-q", "--no-trunc")
|
||||
c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
|
||||
|
||||
}
|
60
integration/image/remove_test.go
Normal file
60
integration/image/remove_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package image // import "github.com/docker/docker/integration/image"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/integration/internal/request"
|
||||
"github.com/docker/docker/internal/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRemoveImageOrphaning(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
ctx := context.Background()
|
||||
client := request.NewAPIClient(t)
|
||||
|
||||
img := "test-container-orphaning"
|
||||
|
||||
// Create a container from busybox, and commit a small change so we have a new image
|
||||
cID1 := container.Create(t, ctx, client, container.WithCmd(""))
|
||||
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
||||
Changes: []string{`ENTRYPOINT ["true"]`},
|
||||
Reference: img,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// verifies that reference now points to first image
|
||||
resp, _, err := client.ImageInspectWithRaw(ctx, img)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, resp.ID, commitResp1.ID)
|
||||
|
||||
// Create a container from created image, and commit a small change with same reference name
|
||||
cID2 := container.Create(t, ctx, client, container.WithImage(img), container.WithCmd(""))
|
||||
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
||||
Changes: []string{`LABEL Maintainer="Integration Tests"`},
|
||||
Reference: img,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// verifies that reference now points to second image
|
||||
resp, _, err = client.ImageInspectWithRaw(ctx, img)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, resp.ID, commitResp2.ID)
|
||||
|
||||
// try to remove the image, should not error out.
|
||||
_, err = client.ImageRemove(ctx, img, types.ImageRemoveOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// check if the first image is still there
|
||||
resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, resp.ID, commitResp1.ID)
|
||||
|
||||
// check if the second image has been deleted
|
||||
_, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID)
|
||||
testutil.ErrorContains(t, err, "No such image:")
|
||||
}
|
Loading…
Add table
Reference in a new issue