Skip to content

Commit

Permalink
integration: Add TestImageInspectEmptyTagsAndDigests
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland committed May 25, 2023
1 parent 26d9cf2 commit d04d4fb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions integration/image/inspect_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package image

import (
"context"
"encoding/json"
"testing"

"github.com/docker/docker/testutil/environment"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip"
)

// Regression test for: https://github.com/moby/moby/issues/45556
func TestImageInspectEmptyTagsAndDigests(t *testing.T) {
skip.If(t, testEnv.OSType == "windows", "build-empty-images is not called on Windows")
defer setupTest(t)()

client := testEnv.APIClient()
ctx := context.Background()

danglingId := environment.DanglingImageIdGraphDriver
if testEnv.UsingSnapshotter() {
danglingId = environment.DanglingImageIdSnapshotter
}

inspect, raw, err := client.ImageInspectWithRaw(ctx, danglingId)
assert.NilError(t, err)

// Must be a zero length array, not null.
assert.Check(t, is.Len(inspect.RepoTags, 0))
assert.Check(t, is.Len(inspect.RepoDigests, 0))

var rawJson map[string]interface{}
err = json.Unmarshal(raw, &rawJson)
assert.NilError(t, err)

// Check if the raw json is also an array, not null.
assert.Check(t, is.Len(rawJson["RepoTags"], 0))
assert.Check(t, is.Len(rawJson["RepoDigests"], 0))
}
3 changes: 3 additions & 0 deletions testutil/environment/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func deleteAllImages(t testing.TB, apiclient client.ImageAPIClient, protectedIma
ctx := context.Background()
for _, image := range images {
tags := tagsFromImageSummary(image)
if _, ok := protectedImages[image.ID]; ok {
continue
}
if len(tags) == 0 {
removeImage(ctx, t, apiclient, image.ID)
continue
Expand Down
1 change: 1 addition & 0 deletions testutil/environment/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func ProtectImages(t testing.TB, testEnv *Execution) {
images = append(images, frozenImages...)
}
testEnv.ProtectImage(t, images...)
testEnv.ProtectImage(t, DanglingImageIdGraphDriver, DanglingImageIdSnapshotter)
}

func getExistingImages(t testing.TB, testEnv *Execution) []string {
Expand Down
7 changes: 7 additions & 0 deletions testutil/environment/special_images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package environment

// Graph driver image store identifies images by the ID of their config.
const DanglingImageIdGraphDriver = "sha256:0df1207206e5288f4a989a2f13d1f5b3c4e70467702c1d5d21dfc9f002b7bd43"

// The containerd image store identifies images by the ID of their manifest/manifest list.
const DanglingImageIdSnapshotter = "sha256:16d365089e5c10e1673ee82ab5bba38ade9b763296ad918bd24b42a1156c5456"

0 comments on commit d04d4fb

Please sign in to comment.