remove_test.go 2.0 KB

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