2018-03-02 17:54:29 -05:00
|
|
|
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"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2018-04-19 05:14:15 -04:00
|
|
|
"gotest.tools/skip"
|
2018-03-02 17:54:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoveImageOrphaning(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
|
2018-03-02 17:54:29 -05:00
|
|
|
defer setupTest(t)()
|
|
|
|
ctx := context.Background()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
img := "test-container-orphaning"
|
|
|
|
|
|
|
|
// Create a container from busybox, and commit a small change so we have a new image
|
2019-06-06 07:00:37 -04:00
|
|
|
cID1 := container.Create(ctx, t, client, container.WithCmd(""))
|
2018-03-02 17:54:29 -05:00
|
|
|
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
|
|
|
Changes: []string{`ENTRYPOINT ["true"]`},
|
|
|
|
Reference: img,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// verifies that reference now points to first image
|
|
|
|
resp, _, err := client.ImageInspectWithRaw(ctx, img)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(resp.ID, commitResp1.ID))
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// Create a container from created image, and commit a small change with same reference name
|
2019-06-06 07:00:37 -04:00
|
|
|
cID2 := container.Create(ctx, t, client, container.WithImage(img), container.WithCmd(""))
|
2018-03-02 17:54:29 -05:00
|
|
|
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
|
|
|
Changes: []string{`LABEL Maintainer="Integration Tests"`},
|
|
|
|
Reference: img,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// verifies that reference now points to second image
|
|
|
|
resp, _, err = client.ImageInspectWithRaw(ctx, img)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(resp.ID, commitResp2.ID))
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// try to remove the image, should not error out.
|
|
|
|
_, err = client.ImageRemove(ctx, img, types.ImageRemoveOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// check if the first image is still there
|
|
|
|
resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(resp.ID, commitResp1.ID))
|
2018-03-02 17:54:29 -05:00
|
|
|
|
|
|
|
// check if the second image has been deleted
|
|
|
|
_, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID)
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, "No such image:"))
|
2018-03-02 17:54:29 -05:00
|
|
|
}
|