github.com/rumpl/bof@v23.0.0-rc.2+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 ) 13 14 func TestRemoveImageOrphaning(t *testing.T) { 15 defer setupTest(t)() 16 ctx := context.Background() 17 client := testEnv.APIClient() 18 19 imgName := strings.ToLower(t.Name()) 20 21 // Create a container from busybox, and commit a small change so we have a new image 22 cID1 := container.Create(ctx, t, client, container.WithCmd("")) 23 commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{ 24 Changes: []string{`ENTRYPOINT ["true"]`}, 25 Reference: imgName, 26 }) 27 assert.NilError(t, err) 28 29 // verifies that reference now points to first image 30 resp, _, err := client.ImageInspectWithRaw(ctx, imgName) 31 assert.NilError(t, err) 32 assert.Check(t, is.Equal(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(ctx, t, client, container.WithImage(imgName), container.WithCmd("")) 36 commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{ 37 Changes: []string{`LABEL Maintainer="Integration Tests"`}, 38 Reference: imgName, 39 }) 40 assert.NilError(t, err) 41 42 // verifies that reference now points to second image 43 resp, _, err = client.ImageInspectWithRaw(ctx, imgName) 44 assert.NilError(t, err) 45 assert.Check(t, is.Equal(resp.ID, commitResp2.ID)) 46 47 // try to remove the image, should not error out. 48 _, err = client.ImageRemove(ctx, imgName, types.ImageRemoveOptions{}) 49 assert.NilError(t, err) 50 51 // check if the first image is still there 52 resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID) 53 assert.NilError(t, err) 54 assert.Check(t, is.Equal(resp.ID, commitResp1.ID)) 55 56 // check if the second image has been deleted 57 _, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID) 58 assert.Check(t, is.ErrorContains(err, "No such image:")) 59 }