mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Fixes ImageList to be retro-compatible with older API
Make sure current client code can talk for ImageList can still talk to older daemon. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
@@ -109,3 +109,51 @@ func TestImageList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageListApiBefore125(t *testing.T) {
|
||||
expectedFilter := "image:tag"
|
||||
client := &Client{
|
||||
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
||||
query := req.URL.Query()
|
||||
actualFilter := query.Get("filter")
|
||||
if actualFilter != expectedFilter {
|
||||
return nil, fmt.Errorf("filter not set in URL query properly. Expected '%s', got %s", expectedFilter, actualFilter)
|
||||
}
|
||||
actualFilters := query.Get("filters")
|
||||
if actualFilters != "" {
|
||||
return nil, fmt.Errorf("filters should have not been present, were with value: %s", actualFilters)
|
||||
}
|
||||
content, err := json.Marshal([]types.ImageSummary{
|
||||
{
|
||||
ID: "image_id2",
|
||||
},
|
||||
{
|
||||
ID: "image_id2",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(content)),
|
||||
}, nil
|
||||
}),
|
||||
version: "1.24",
|
||||
}
|
||||
|
||||
filters := filters.NewArgs()
|
||||
filters.Add("reference", "image:tag")
|
||||
|
||||
options := types.ImageListOptions{
|
||||
Filters: filters,
|
||||
}
|
||||
|
||||
images, err := client.ImageList(context.Background(), options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(images) != 2 {
|
||||
t.Fatalf("expected 2 images, got %v", images)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user