From dea29e7c999b7ef76a816867a2cb75c2da658fa2 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 5 Jul 2013 16:58:39 +0000 Subject: [PATCH] Fix error in rmi when conflict --- api_test.go | 18 ++++++++++++++---- server.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api_test.go b/api_test.go index f827826430..6eb2584b01 100644 --- a/api_test.go +++ b/api_test.go @@ -1359,21 +1359,31 @@ func TestDeleteImages(t *testing.T) { t.Errorf("Expected %d images, %d found", len(initialImages)+1, len(images)) } - req, err := http.NewRequest("DELETE", "/images/test:test", nil) + req, err := http.NewRequest("DELETE", "/images/"+unitTestImageID, nil) if err != nil { t.Fatal(err) } r := httptest.NewRecorder() - if err := deleteImages(srv, APIVERSION, r, req, map[string]string{"name": "test:test"}); err != nil { + if err := deleteImages(srv, APIVERSION, r, req, map[string]string{"name": unitTestImageID}); err == nil { + t.Fatalf("Expected conflict error, got none") + } + + req2, err := http.NewRequest("DELETE", "/images/test:test", nil) + if err != nil { t.Fatal(err) } - if r.Code != http.StatusOK { + + r2 := httptest.NewRecorder() + if err := deleteImages(srv, APIVERSION, r2, req2, map[string]string{"name": "test:test"}); err != nil { + t.Fatal(err) + } + if r2.Code != http.StatusOK { t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code) } var outs []APIRmi - if err := json.Unmarshal(r.Body.Bytes(), &outs); err != nil { + if err := json.Unmarshal(r2.Body.Bytes(), &outs); err != nil { t.Fatal(err) } if len(outs) != 1 { diff --git a/server.go b/server.go index 4e30ad6c5d..9e573b2321 100644 --- a/server.go +++ b/server.go @@ -919,7 +919,7 @@ func (srv *Server) deleteImageParents(img *Image, imgs *[]APIRmi) error { func (srv *Server) deleteImage(img *Image, repoName, tag string) ([]APIRmi, error) { //Untag the current image - var imgs []APIRmi + imgs := []APIRmi{} tagDeleted, err := srv.runtime.repositories.Delete(repoName, tag) if err != nil { return nil, err