mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: TestImageList: use subtests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -35,11 +35,13 @@ func TestImageListConnectionError(t *testing.T) {
|
||||
func TestImageList(t *testing.T) {
|
||||
const expectedURL = "/images/json"
|
||||
|
||||
listCases := []struct {
|
||||
tests := []struct {
|
||||
doc string
|
||||
options ImageListOptions
|
||||
expectedQueryParams map[string]string
|
||||
}{
|
||||
{
|
||||
doc: "no options",
|
||||
options: ImageListOptions{},
|
||||
expectedQueryParams: map[string]string{
|
||||
"all": "",
|
||||
@@ -48,6 +50,7 @@ func TestImageList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
doc: "label filters and dangling",
|
||||
options: ImageListOptions{
|
||||
Filters: make(Filters).
|
||||
Add("label", "label1").
|
||||
@@ -61,6 +64,7 @@ func TestImageList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
doc: "label filters no dangling",
|
||||
options: ImageListOptions{
|
||||
Filters: make(Filters).Add("dangling", "false"),
|
||||
},
|
||||
@@ -71,13 +75,14 @@ func TestImageList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, listCase := range listCases {
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.doc, func(t *testing.T) {
|
||||
client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
|
||||
if err := assertRequest(req, http.MethodGet, expectedURL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
query := req.URL.Query()
|
||||
for key, expected := range listCase.expectedQueryParams {
|
||||
for key, expected := range tc.expectedQueryParams {
|
||||
actual := query.Get(key)
|
||||
if actual != expected {
|
||||
return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
|
||||
@@ -89,10 +94,12 @@ func TestImageList(t *testing.T) {
|
||||
})(req)
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
defer func() { _ = client.Close() }()
|
||||
|
||||
images, err := client.ImageList(t.Context(), listCase.options)
|
||||
images, err := client.ImageList(t.Context(), tc.options)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(images.Items, 2))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user