prune_test.go 939 B

123456789101112131415161718192021222324252627282930313233
  1. package image
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/docker/docker/api/types/filters"
  6. "github.com/docker/docker/integration/internal/container"
  7. "github.com/docker/docker/testutil/environment"
  8. "gotest.tools/v3/assert"
  9. is "gotest.tools/v3/assert/cmp"
  10. "gotest.tools/v3/skip"
  11. )
  12. // Regression test for: https://github.com/moby/moby/issues/45732
  13. func TestPruneDontDeleteUsedDangling(t *testing.T) {
  14. skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: hack/make/.build-empty-images doesn't run on Windows")
  15. defer setupTest(t)()
  16. client := testEnv.APIClient()
  17. ctx := context.Background()
  18. danglingID := environment.GetTestDanglingImageId(testEnv)
  19. container.Create(ctx, t, client,
  20. container.WithImage(danglingID),
  21. container.WithCmd("sleep", "60"))
  22. pruned, err := client.ImagesPrune(ctx, filters.NewArgs(filters.Arg("dangling", "true")))
  23. assert.NilError(t, err)
  24. assert.Check(t, is.Len(pruned.ImagesDeleted, 0))
  25. }