From 5007c36d71ac86f5b47b6ba10a5ed6e841807284 Mon Sep 17 00:00:00 2001 From: zhangyue Date: Sat, 10 Nov 2018 11:00:26 +0800 Subject: [PATCH] cli: fix images filter when use multi reference filter Signed-off-by: zhangyue --- daemon/images/images.go | 3 ++ integration/image/list_test.go | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 integration/image/list_test.go diff --git a/daemon/images/images.go b/daemon/images/images.go index d1ca978f3b..d17a2e2455 100644 --- a/daemon/images/images.go +++ b/daemon/images/images.go @@ -152,6 +152,9 @@ func (i *ImageService) Images(imageFilters filters.Args, all bool, withExtraAttr if matchErr != nil { return nil, matchErr } + if found { + break + } } if !found { continue diff --git a/integration/image/list_test.go b/integration/image/list_test.go new file mode 100644 index 0000000000..9d6ce16537 --- /dev/null +++ b/integration/image/list_test.go @@ -0,0 +1,50 @@ +package image // import "github.com/docker/docker/integration/image" + +import ( + "context" + "testing" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/internal/test/request" + "gotest.tools/assert" + is "gotest.tools/assert/cmp" +) + +// Regression : #38171 +func TestImagesFilterMultiReference(t *testing.T) { + defer setupTest(t)() + client := request.NewAPIClient(t) + ctx := context.Background() + + name := "images_filter_multi_reference" + repoTags := []string{ + name + ":v1", + name + ":v2", + name + ":v3", + name + ":v4", + } + + for _, repoTag := range repoTags { + err := client.ImageTag(ctx, "busybox:latest", repoTag) + assert.NilError(t, err) + } + + filter := filters.NewArgs() + filter.Add("reference", repoTags[0]) + filter.Add("reference", repoTags[1]) + filter.Add("reference", repoTags[2]) + options := types.ImageListOptions{ + All: false, + Filters: filter, + } + images, err := client.ImageList(ctx, options) + assert.NilError(t, err) + + assert.Check(t, is.Equal(len(images[0].RepoTags), 3)) + for _, repoTag := range images[0].RepoTags { + if repoTag != repoTags[0] && repoTag != repoTags[1] && repoTag != repoTags[2] { + t.Errorf("list images doesn't match any repoTag we expected, repoTag: %s", repoTag) + } + } +}