Browse Source

integration: Add TestImageInspectEmptyTagsAndDigests

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 2 years ago
parent
commit
6506579e18

+ 41 - 0
integration/image/inspect_test.go

@@ -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 - 0
testutil/environment/clean.go

@@ -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

+ 1 - 0
testutil/environment/protect.go

@@ -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 {

+ 7 - 0
testutil/environment/special_images.go

@@ -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"