mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51498 from 2003Aditya/TestAPIImagesDelete
Test api images delete
This commit is contained in:
@@ -36,30 +36,6 @@ func (s *DockerAPISuite) TestAPIImagesSaveAndLoad(c *testing.T) {
|
||||
assert.Equal(c, strings.TrimSpace(inspectOut), id, "load did not work properly")
|
||||
}
|
||||
|
||||
func (s *DockerAPISuite) TestAPIImagesDelete(c *testing.T) {
|
||||
apiClient, err := client.New(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer apiClient.Close()
|
||||
|
||||
if testEnv.DaemonInfo.OSType != "windows" {
|
||||
testRequires(c, Network)
|
||||
}
|
||||
name := "test-api-images-delete"
|
||||
cli.BuildCmd(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
||||
id := getIDByName(c, name)
|
||||
|
||||
cli.DockerCmd(c, "tag", name, "test:tag1")
|
||||
|
||||
_, err = apiClient.ImageRemove(testutil.GetContext(c), id, client.ImageRemoveOptions{})
|
||||
assert.ErrorContains(c, err, "unable to delete")
|
||||
|
||||
_, err = apiClient.ImageRemove(testutil.GetContext(c), "test:noexist", client.ImageRemoveOptions{})
|
||||
assert.ErrorContains(c, err, "No such image")
|
||||
|
||||
_, err = apiClient.ImageRemove(testutil.GetContext(c), "test:tag1", client.ImageRemoveOptions{})
|
||||
assert.NilError(c, err)
|
||||
}
|
||||
|
||||
func (s *DockerAPISuite) TestAPIImagesImportBadSrc(c *testing.T) {
|
||||
testRequires(c, Network, testEnv.IsLocalDaemon)
|
||||
|
||||
|
||||
@@ -9,8 +9,11 @@ import (
|
||||
|
||||
"github.com/moby/moby/api/types/image"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/client/pkg/stringid"
|
||||
build "github.com/moby/moby/v2/integration/internal/build"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
iimage "github.com/moby/moby/v2/integration/internal/image"
|
||||
"github.com/moby/moby/v2/internal/testutil/fakecontext"
|
||||
"github.com/moby/moby/v2/internal/testutil/specialimage"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -176,3 +179,39 @@ func checkPlatformDeleted(t *testing.T, imageIdx *ocispec.Index, resp []image.De
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIImagesDelete(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
const name = "test-api-images-delete"
|
||||
|
||||
buildCtx := fakecontext.New(t, t.TempDir(),
|
||||
fakecontext.WithDockerfile(`FROM busybox
|
||||
ENV FOO=bar`))
|
||||
defer buildCtx.Close()
|
||||
|
||||
imgID := build.Do(ctx, t, apiClient, buildCtx)
|
||||
|
||||
// Cleanup always runs
|
||||
defer func() {
|
||||
_, _ = apiClient.ImageRemove(ctx, imgID, client.ImageRemoveOptions{Force: true})
|
||||
}()
|
||||
|
||||
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: imgID, Target: name})
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: imgID, Target: "test:tag1"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = apiClient.ImageRemove(ctx, imgID, client.ImageRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsConflict))
|
||||
assert.Check(t, is.ErrorContains(err, "unable to delete "+stringid.TruncateID(imgID)))
|
||||
|
||||
_, err = apiClient.ImageRemove(ctx, "test:noexist", client.ImageRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorContains(err, "No such image: test:noexist"))
|
||||
|
||||
_, err = apiClient.ImageRemove(ctx, "test:tag1", client.ImageRemoveOptions{})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user