mirror of https://github.com/docker/docs.git
Reusing ImageListOptions for ImageFilterOptions
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
ebdbefecda
commit
8a003a5fa8
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue