client: support multiple platforms on save and load

We don't yet support this at the API level, so for now it returns
an error when trying to set multiple, but this makes sure that the
client types are already ready for this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-10-28 18:03:54 +01:00
parent 84ad184fe5
commit 9c9eccfb23
7 changed files with 73 additions and 16 deletions

View File

@@ -34,7 +34,7 @@ func TestImageLoad(t *testing.T) {
tests := []struct {
doc string
quiet bool
platform *ocispec.Platform
platforms []ocispec.Platform
responseContentType string
expectedResponseJSON bool
expectedQueryParams url.Values
@@ -59,7 +59,7 @@ func TestImageLoad(t *testing.T) {
},
{
doc: "json with platform",
platform: &ocispec.Platform{Architecture: "arm64", OS: "linux", Variant: "v8"},
platforms: []ocispec.Platform{{Architecture: "arm64", OS: "linux", Variant: "v8"}},
responseContentType: "application/json",
expectedResponseJSON: true,
expectedQueryParams: url.Values{
@@ -67,6 +67,19 @@ func TestImageLoad(t *testing.T) {
"quiet": {"0"},
},
},
{
doc: "json with multiple platforms",
platforms: []ocispec.Platform{
{Architecture: "arm64", OS: "linux", Variant: "v8"},
{Architecture: "amd64", OS: "linux"},
},
responseContentType: "application/json",
expectedResponseJSON: true,
expectedQueryParams: url.Values{
"platform": {`{"architecture":"arm64","os":"linux","variant":"v8"}`, `{"architecture":"amd64","os":"linux"}`},
"quiet": {"0"},
},
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
@@ -85,8 +98,8 @@ func TestImageLoad(t *testing.T) {
input := bytes.NewReader([]byte(expectedInput))
imageLoadResponse, err := client.ImageLoad(context.Background(), input, image.LoadOptions{
Quiet: tc.quiet,
Platform: tc.platform,
Quiet: tc.quiet,
Platforms: tc.platforms,
})
assert.NilError(t, err)
assert.Check(t, is.Equal(imageLoadResponse.JSON, tc.expectedResponseJSON))