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