github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/integration/image/remove_test.go (about) 1 package image // import "github.com/docker/docker/integration/image" 2 3 import ( 4 "context" 5 "strings" 6 "testing" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/integration/internal/container" 10 "gotest.tools/v3/assert" 11 is "gotest.tools/v3/assert/cmp" 12 "gotest.tools/v3/skip" 13 ) 14 15 func TestRemoveImageOrphaning(t *testing.T) { 16 skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME") 17 defer setupTest(t)() 18 ctx := context.Background() 19 client := testEnv.APIClient() 20 21 imgName := strings.ToLower(t.Name()) 22 23 // Create a container from busybox, and commit a small change so we have a new image 24 cID1 := container.Create(ctx, t, client, container.WithCmd("")) 25 commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{ 26 Changes: []string{`ENTRYPOINT ["true"]`}, 27 Reference: imgName, 28 }) 29 assert.NilError(t, err) 30 31 // verifies that reference now points to first image 32 resp, _, err := client.ImageInspectWithRaw(ctx, imgName) 33 assert.NilError(t, err) 34 assert.Check(t, is.Equal(resp.ID, commitResp1.ID)) 35 36 // Create a container from created image, and commit a small change with same reference name 37 cID2 := container.Create(ctx, t, client, container.WithImage(imgName), container.WithCmd("")) 38 commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{ 39 Changes: []string{`LABEL Maintainer="Integration Tests"`}, 40 Reference: imgName, 41 }) 42 assert.NilError(t, err) 43 44 // verifies that reference now points to second image 45 resp, _, err = client.ImageInspectWithRaw(ctx, imgName) 46 assert.NilError(t, err) 47 assert.Check(t, is.Equal(resp.ID, commitResp2.ID)) 48 49 // try to remove the image, should not error out. 50 _, err = client.ImageRemove(ctx, imgName, types.ImageRemoveOptions{}) 51 assert.NilError(t, err) 52 53 // check if the first image is still there 54 resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID) 55 assert.NilError(t, err) 56 assert.Check(t, is.Equal(resp.ID, commitResp1.ID)) 57 58 // check if the second image has been deleted 59 _, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID) 60 assert.Check(t, is.ErrorContains(err, "No such image:")) 61 }