moby/integration/image/inspect_test.go
Paweł Gronowski e2bade43e7
testutil/environment: Add GetTestDanglingImageId
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit a96e6044cc)
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
2023-06-30 10:31:43 -06:00

38 lines
1 KiB
Go

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.GetTestDanglingImageId(testEnv)
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))
}