client: TestImageListWithSharedSize: merge with TestImageList

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-13 15:49:55 +01:00
parent 62589a6961
commit 94e83af71a

View File

@@ -3,7 +3,6 @@ package client
import (
"fmt"
"net/http"
"net/url"
"testing"
cerrdefs "github.com/containerd/errdefs"
@@ -74,6 +73,15 @@ func TestImageList(t *testing.T) {
"filters": `{"dangling":{"false":true}}`,
},
},
{
doc: "with shared size",
options: ImageListOptions{
SharedSize: true,
},
expectedQueryParams: map[string]string{
"shared-size": "1",
},
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
@@ -102,37 +110,3 @@ func TestImageList(t *testing.T) {
})
}
}
// Checks if shared-size query parameter is set/not being set correctly
// for /images/json.
func TestImageListWithSharedSize(t *testing.T) {
t.Parallel()
const sharedSize = "shared-size"
for _, tc := range []struct {
name string
version string
options ImageListOptions
sharedSize string // expected value for the shared-size query param, or empty if it should not be set.
}{
{name: "unset, no options set"},
{name: "set", options: ImageListOptions{SharedSize: true}, sharedSize: "1"},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var query url.Values
client, err := New(
WithAPIVersion(tc.version),
WithMockClient(func(req *http.Request) (*http.Response, error) {
query = req.URL.Query()
return mockResponse(http.StatusOK, nil, "[]")(req)
}),
)
assert.NilError(t, err)
_, err = client.ImageList(t.Context(), tc.options)
assert.NilError(t, err)
expectedSet := tc.sharedSize != ""
assert.Check(t, is.Equal(query.Has(sharedSize), expectedSet))
assert.Check(t, is.Equal(query.Get(sharedSize), tc.sharedSize))
})
}
}