mirror of
https://github.com/moby/moby.git
synced 2026-08-04 15:11:00 +00:00
commit 4dc961d0e9 removed deprecated
fields from the image inspect response for API v1.50 and up. As
part of that change, it changed the type used for the Config field
to use the docker image spect structs, which embeds the OCI image
spec structs.
While the OCI image spect struct contains the same fields as we
used before, those fields also have "omitempty" set, which means
they are now omitted when empty.
We should probably consider deprecating that behavior in the API,
and call out that these fields are omitted if not set, but in the
meantime, we can add them back with their default (zero) value.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package image
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types/image"
|
|
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
|
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestInspectResponse(t *testing.T) {
|
|
tests := []struct {
|
|
doc string
|
|
cfg *ocispec.ImageConfig
|
|
legacyConfig map[string]any
|
|
expected string
|
|
}{
|
|
{
|
|
doc: "empty",
|
|
expected: `null`,
|
|
},
|
|
{
|
|
doc: "no legacy config",
|
|
cfg: &ocispec.ImageConfig{
|
|
Cmd: []string{"/bin/sh"},
|
|
StopSignal: "SIGQUIT",
|
|
},
|
|
expected: `{"Cmd":["/bin/sh"],"StopSignal":"SIGQUIT"}`,
|
|
},
|
|
{
|
|
doc: "api < v1.50",
|
|
cfg: &ocispec.ImageConfig{
|
|
Cmd: []string{"/bin/sh"},
|
|
StopSignal: "SIGQUIT",
|
|
},
|
|
legacyConfig: legacyConfigFields["v1.49"],
|
|
expected: `{"AttachStderr":false,"AttachStdin":false,"AttachStdout":false,"Cmd":["/bin/sh"],"Domainname":"","Entrypoint":null,"Env":null,"Hostname":"","Image":"","Labels":null,"OnBuild":null,"OpenStdin":false,"StdinOnce":false,"StopSignal":"SIGQUIT","Tty":false,"User":"","Volumes":null,"WorkingDir":""}`,
|
|
},
|
|
{
|
|
doc: "api >= v1.50",
|
|
cfg: &ocispec.ImageConfig{
|
|
Cmd: []string{"/bin/sh"},
|
|
StopSignal: "SIGQUIT",
|
|
},
|
|
legacyConfig: legacyConfigFields["current"],
|
|
expected: `{"Cmd":["/bin/sh"],"Entrypoint":null,"Env":null,"Labels":null,"OnBuild":null,"StopSignal":"SIGQUIT","User":"","Volumes":null,"WorkingDir":""}`,
|
|
},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.doc, func(t *testing.T) {
|
|
imgInspect := &image.InspectResponse{}
|
|
if tc.cfg != nil {
|
|
// Verify that fields that are set override the legacy values,
|
|
// or appended if not part of the legacy values.
|
|
imgInspect.Config = &dockerspec.DockerOCIImageConfig{
|
|
ImageConfig: *tc.cfg,
|
|
}
|
|
}
|
|
out, err := json.Marshal(&inspectCompatResponse{
|
|
InspectResponse: imgInspect,
|
|
legacyConfig: tc.legacyConfig,
|
|
})
|
|
assert.NilError(t, err)
|
|
|
|
var outMap struct{ Config json.RawMessage }
|
|
err = json.Unmarshal(out, &outMap)
|
|
assert.NilError(t, err)
|
|
assert.Check(t, is.Equal(string(outMap.Config), tc.expected))
|
|
})
|
|
}
|
|
}
|