From 8a003a5fa84adbb3c55f8943100c04395da01a97 Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Wed, 30 Mar 2016 11:00:05 -0700 Subject: [PATCH] Reusing ImageListOptions for ImageFilterOptions Signed-off-by: Nishant Totla --- api/handlers.go | 8 +++++--- cluster/image.go | 10 +++------- cluster/image_test.go | 16 +++++----------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index d08fb5453a..a2d002d944 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -187,9 +187,11 @@ func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) { // but still keeps their Engine infos as an array. groupImages := make(map[string]apitypes.Image) opts := cluster.ImageFilterOptions{ - All: boolValue(r, "all"), - NameFilter: r.FormValue("filter"), - Filters: filters, + apitypes.ImageListOptions{ + All: boolValue(r, "all"), + MatchName: r.FormValue("filter"), + Filters: filters, + }, } for _, image := range c.cluster.Images().Filter(opts) { if len(accepteds) != 0 { diff --git a/cluster/image.go b/cluster/image.go index 8bd73c252e..2b4be40992 100644 --- a/cluster/image.go +++ b/cluster/image.go @@ -4,7 +4,6 @@ import ( "strings" "github.com/docker/engine-api/types" - dockerfilters "github.com/docker/engine-api/types/filters" ) // Image is exported @@ -80,11 +79,8 @@ func (image *Image) Match(IDOrName string, matchTag bool) bool { // ImageFilterOptions is the set of filtering options supported by // Images.Filter() -// FIXMEENGINEAPI: should either embed or be replaced by types.ImageListOptions type ImageFilterOptions struct { - All bool - NameFilter string - Filters dockerfilters.Args + types.ImageListOptions } // Images is a collection of Image objects that can be filtered @@ -108,12 +104,12 @@ func (images Images) Filter(opts ImageFilterOptions) Images { } includeRepoFilter := func(image *Image) bool { - if opts.NameFilter == "" { + if opts.MatchName == "" { return true } for _, repoTag := range image.RepoTags { repoName, _ := ParseRepositoryTag(repoTag) - if repoTag == opts.NameFilter || repoName == opts.NameFilter { + if repoTag == opts.MatchName || repoName == opts.MatchName { return true } } diff --git a/cluster/image_test.go b/cluster/image_test.go index 7fd9233615..d9d56e9721 100644 --- a/cluster/image_test.go +++ b/cluster/image_test.go @@ -68,12 +68,12 @@ func TestImagesFilterWithLabelFilter(t *testing.T) { filters := dockerfilters.NewArgs() filters.Add("label", "com.example.project=bar") - result := images.Filter(ImageFilterOptions{All: true, Filters: filters}) + result := images.Filter(ImageFilterOptions{types.ImageListOptions{All: true, Filters: filters}}) assert.Equal(t, len(result), 1) assert.Equal(t, result[0].ID, "b") } -func TestImagesFilterWithNameFilter(t *testing.T) { +func TestImagesFilterWithMatchName(t *testing.T) { engine := NewEngine("test", 0, engOpts) images := Images{ { @@ -89,15 +89,12 @@ func TestImagesFilterWithNameFilter(t *testing.T) { }, } - result := images.Filter(ImageFilterOptions{ - All: true, - NameFilter: "example:2", - }) + result := images.Filter(ImageFilterOptions{types.ImageListOptions{All: true, MatchName: "example:2"}}) assert.Equal(t, len(result), 1) assert.Equal(t, result[0].ID, "a") } -func TestImagesFilterWithNameFilterWithTag(t *testing.T) { +func TestImagesFilterWithMatchNameWithTag(t *testing.T) { engine := NewEngine("test", 0, engOpts) images := Images{ { @@ -117,10 +114,7 @@ func TestImagesFilterWithNameFilterWithTag(t *testing.T) { }, } - result := images.Filter(ImageFilterOptions{ - All: true, - NameFilter: "example", - }) + result := images.Filter(ImageFilterOptions{types.ImageListOptions{All: true, MatchName: "example"}}) assert.Equal(t, len(result), 2) }