mirror of https://github.com/docker/docs.git
Merge branch 'filter' of https://github.com/reds/docker into reds-filter
This commit is contained in:
commit
843f9091f2
|
@ -209,8 +209,10 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
||||||
}
|
}
|
||||||
outs := []APIImages{} //produce [] when empty instead of 'null'
|
outs := []APIImages{} //produce [] when empty instead of 'null'
|
||||||
for name, repository := range srv.runtime.repositories.Repositories {
|
for name, repository := range srv.runtime.repositories.Repositories {
|
||||||
if filter != "" && name != filter {
|
if filter != "" {
|
||||||
continue
|
if match, _ := path.Match(filter, name); !match {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for tag, id := range repository {
|
for tag, id := range repository {
|
||||||
var out APIImages
|
var out APIImages
|
||||||
|
@ -678,7 +680,7 @@ func (srv *Server) getImageList(localRepo map[string]string) ([][]*registry.ImgD
|
||||||
depGraph.NewNode(img.ID)
|
depGraph.NewNode(img.ID)
|
||||||
img.WalkHistory(func(current *Image) error {
|
img.WalkHistory(func(current *Image) error {
|
||||||
imgList[current.ID] = ®istry.ImgData{
|
imgList[current.ID] = ®istry.ImgData{
|
||||||
ID: current.ID,
|
ID: current.ID,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
}
|
}
|
||||||
parent, err := current.GetParent()
|
parent, err := current.GetParent()
|
||||||
|
|
|
@ -431,3 +431,57 @@ func TestRmi(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImagesFilter(t *testing.T) {
|
||||||
|
runtime := mkRuntime(t)
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := srv.runtime.repositories.Set("utest:5000/docker", "tag3", unitTestImageName, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err := srv.Images(false, "utest*/*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(images) != 2 {
|
||||||
|
t.Fatal("incorrect number of matches returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err = srv.Images(false, "utest")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(images) != 1 {
|
||||||
|
t.Fatal("incorrect number of matches returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err = srv.Images(false, "utest*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(images) != 1 {
|
||||||
|
t.Fatal("incorrect number of matches returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err = srv.Images(false, "*5000*/*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(images) != 1 {
|
||||||
|
t.Fatal("incorrect number of matches returned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue