mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1328 from dotcloud/1307_url_port_delete-fix
Use utils.ParseRepositoryTag instead of strings.Split(name, ":") in server.ImageDelete
This commit is contained in:
commit
0c0077ed6f
4 changed files with 41 additions and 14 deletions
7
api.go
7
api.go
|
@ -793,12 +793,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
remoteURL := r.FormValue("remote")
|
remoteURL := r.FormValue("remote")
|
||||||
repoName := r.FormValue("t")
|
repoName := r.FormValue("t")
|
||||||
rawSuppressOutput := r.FormValue("q")
|
rawSuppressOutput := r.FormValue("q")
|
||||||
tag := ""
|
repoName, tag := utils.ParseRepositoryTag(repoName)
|
||||||
if strings.Contains(repoName, ":") {
|
|
||||||
remoteParts := strings.Split(repoName, ":")
|
|
||||||
tag = remoteParts[1]
|
|
||||||
repoName = remoteParts[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
var context io.Reader
|
var context io.Reader
|
||||||
|
|
||||||
|
|
|
@ -977,13 +977,7 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag string
|
name, tag := utils.ParseRepositoryTag(name)
|
||||||
if strings.Contains(name, ":") {
|
|
||||||
nameParts := strings.Split(name, ":")
|
|
||||||
name = nameParts[0]
|
|
||||||
tag = nameParts[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return srv.deleteImage(img, name, tag)
|
return srv.deleteImage(img, name, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,20 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
||||||
t.Fatal(err)
|
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, "")
|
images, err := srv.Images(false, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != len(initialImages)+2 {
|
if len(images) != len(initialImages)+3 {
|
||||||
t.Errorf("Expected %d images, %d found", len(initialImages)+2, len(images))
|
t.Errorf("Expected %d images, %d found", len(initialImages)+2, len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +47,19 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(images) != len(initialImages)+2 {
|
||||||
|
t.Errorf("Expected %d images, %d found", len(initialImages)+2, len(images))
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := srv.ImageDelete("utest:5000/docker:tag3", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
images, err = srv.Images(false, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if len(images) != len(initialImages)+1 {
|
if len(images) != len(initialImages)+1 {
|
||||||
t.Errorf("Expected %d images, %d found", len(initialImages)+1, len(images))
|
t.Errorf("Expected %d images, %d found", len(initialImages)+1, len(images))
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,3 +282,24 @@ func TestParseHost(t *testing.T) {
|
||||||
t.Errorf("unix:///var/run/docker.sock -> expected unix:///var/run/docker.sock, got %s", addr)
|
t.Errorf("unix:///var/run/docker.sock -> expected unix:///var/run/docker.sock, got %s", addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseRepositoryTag(t *testing.T) {
|
||||||
|
if repo, tag := ParseRepositoryTag("root"); repo != "root" || tag != "" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "root", "", repo, tag)
|
||||||
|
}
|
||||||
|
if repo, tag := ParseRepositoryTag("root:tag"); repo != "root" || tag != "tag" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "root", "tag", repo, tag)
|
||||||
|
}
|
||||||
|
if repo, tag := ParseRepositoryTag("user/repo"); repo != "user/repo" || tag != "" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "user/repo", "", repo, tag)
|
||||||
|
}
|
||||||
|
if repo, tag := ParseRepositoryTag("user/repo:tag"); repo != "user/repo" || tag != "tag" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "user/repo", "tag", repo, tag)
|
||||||
|
}
|
||||||
|
if repo, tag := ParseRepositoryTag("url:5000/repo"); repo != "url:5000/repo" || tag != "" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "url:5000/repo", "", repo, tag)
|
||||||
|
}
|
||||||
|
if repo, tag := ParseRepositoryTag("url:5000/repo:tag"); repo != "url:5000/repo" || tag != "tag" {
|
||||||
|
t.Errorf("Expected repo: '%s' and tag: '%s', got '%s' and '%s'", "url:5000/repo", "tag", repo, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue