Files
moby/client/utils_test.go
Sebastiaan van Stijn 839e46f97c client: remove support for API < v1.22 filter format
The format for filters changed in 93d1dd8036
(docker v1.10 / API v1.22). As part of that implementation, the daemon
would parse the new format, and fall back to parsing the old format if
this failed. This fallback was not based on API version, so any version
of the API released since would continue to accept both the legacy and
curent format.

For the client, the change in format caused a regression when connecting
to an older daemon; a `ToParamWithVersion` utility was introduced in
[docker/engine-api@81388f0] to produce the old format when the client was
connected to a docker v1.9 or older daemon, using an old API version.

Given that any version of docker 1.10 or above would support both formats,
regardless of the API version used, and API v1.22 is no longer supported,
it should be safe to assume we can drop the version-specific format in the
client. Even if the client would be using API v1.22 (or older), the format
would only be necessary for an actual docker v1.9 daemon, which would be
very unlikely, and a daemon that's 9 Years old.

[docker/engine-api@81388f0]: 81388f00dd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-15 21:27:58 +02:00

58 lines
1.6 KiB
Go

package client
import (
"testing"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestEncodePlatforms(t *testing.T) {
tests := []struct {
doc string
platforms []ocispec.Platform
expected []string
}{
{
doc: "single platform",
platforms: []ocispec.Platform{
{Architecture: "arm64", OS: "windows", Variant: "v8", OSVersion: "99.99.99"},
},
expected: []string{
`{"architecture":"arm64","os":"windows","os.version":"99.99.99","variant":"v8"}`,
},
},
{
doc: "multiple platforms",
platforms: []ocispec.Platform{
{Architecture: "arm64", OS: "linux", Variant: "v8"},
{Architecture: "arm64", OS: "windows", Variant: "v8", OSVersion: "99.99.99"},
},
expected: []string{
`{"architecture":"arm64","os":"linux","variant":"v8"}`,
`{"architecture":"arm64","os":"windows","os.version":"99.99.99","variant":"v8"}`,
},
},
{
doc: "multiple platforms with duplicates",
platforms: []ocispec.Platform{
{Architecture: "arm64", OS: "linux", Variant: "v8"},
{Architecture: "arm64", OS: "windows", Variant: "v8", OSVersion: "99.99.99"},
{Architecture: "arm64", OS: "linux", Variant: "v8"},
},
expected: []string{
`{"architecture":"arm64","os":"linux","variant":"v8"}`,
`{"architecture":"arm64","os":"windows","os.version":"99.99.99","variant":"v8"}`,
},
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
out, err := encodePlatforms(tc.platforms...)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(out, tc.expected))
})
}
}