From 6506579e18f7880b2f3db1966fa728f91a102514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 22 May 2023 11:48:50 +0200 Subject: [PATCH] integration: Add TestImageInspectEmptyTagsAndDigests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- integration/image/inspect_test.go | 41 ++++++++++++++++++++++++++ testutil/environment/clean.go | 3 ++ testutil/environment/protect.go | 1 + testutil/environment/special_images.go | 7 +++++ 4 files changed, 52 insertions(+) create mode 100644 integration/image/inspect_test.go create mode 100644 testutil/environment/special_images.go diff --git a/integration/image/inspect_test.go b/integration/image/inspect_test.go new file mode 100644 index 0000000000..519e824c47 --- /dev/null +++ b/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)) +} diff --git a/testutil/environment/clean.go b/testutil/environment/clean.go index 29448bb7b5..e837427655 100644 --- a/testutil/environment/clean.go +++ b/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 diff --git a/testutil/environment/protect.go b/testutil/environment/protect.go index 2a0d5281b6..a84dccc9a5 100644 --- a/testutil/environment/protect.go +++ b/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 { diff --git a/testutil/environment/special_images.go b/testutil/environment/special_images.go new file mode 100644 index 0000000000..b486e0498c --- /dev/null +++ b/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"