mirror of
https://github.com/moby/moby.git
synced 2026-07-24 08:22:47 +00:00
Merge pull request #48777 from vvoland/c8d-inspect-duplicate-repodigests
c8d/inspect: Fix duplicate RepoDigests
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
imagetypes "github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/api/types/storage"
|
||||
"github.com/docker/docker/internal/sliceutil"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"golang.org/x/sync/semaphore"
|
||||
)
|
||||
@@ -103,7 +104,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, _ backe
|
||||
return &imagetypes.InspectResponse{
|
||||
ID: img.ImageID(),
|
||||
RepoTags: repoTags,
|
||||
RepoDigests: repoDigests,
|
||||
RepoDigests: sliceutil.Dedup(repoDigests),
|
||||
Parent: img.Parent.String(),
|
||||
Comment: comment,
|
||||
Created: created,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/internal/testutils/specialimage"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -34,3 +35,27 @@ func TestImageInspectEmptyTagsAndDigests(t *testing.T) {
|
||||
assert.Check(t, is.Len(rawJson["RepoTags"], 0))
|
||||
assert.Check(t, is.Len(rawJson["RepoDigests"], 0))
|
||||
}
|
||||
|
||||
// Regression test for: https://github.com/moby/moby/issues/48747
|
||||
func TestImageInspectUniqueRepoDigests(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
|
||||
client := testEnv.APIClient()
|
||||
|
||||
before, _, err := client.ImageInspectWithRaw(ctx, "busybox")
|
||||
assert.NilError(t, err)
|
||||
|
||||
for _, tag := range []string{"master", "newest"} {
|
||||
imgName := "busybox:" + tag
|
||||
err := client.ImageTag(ctx, "busybox", imgName)
|
||||
assert.NilError(t, err)
|
||||
defer func() {
|
||||
_, _ = client.ImageRemove(ctx, imgName, image.RemoveOptions{Force: true})
|
||||
}()
|
||||
}
|
||||
|
||||
after, _, err := client.ImageInspectWithRaw(ctx, "busybox")
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Len(after.RepoDigests, len(before.RepoDigests)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user