See: https://github.com/docker/docker/issues/10867
While looking at #10867 I noticed that the error message generated for
a blank image ID wasn't very helpful so this fixes that.
Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -41,6 +41,10 @@ func (daemon *Daemon) DeleteImage(eng *engine.Engine, name string, imgs *engine. |
| 41 | 41 |
tag = graph.DEFAULTTAG |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
+ if name == "" {
|
|
| 45 |
+ return fmt.Errorf("Image name can not be blank")
|
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 44 | 48 |
img, err := daemon.Repositories().LookupImage(name) |
| 45 | 49 |
if err != nil {
|
| 46 | 50 |
if r, _ := daemon.Repositories().Get(repoName); r != nil {
|
| ... | ... |
@@ -155,5 +155,19 @@ func TestRmiWithMultipleRepositories(t *testing.T) {
|
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
logDone("rmi - delete a image which its dependency tagged to multiple repositories success")
|
| 158 |
+} |
|
| 159 |
+ |
|
| 160 |
+func TestRmiBlank(t *testing.T) {
|
|
| 161 |
+ // try to delete a blank image name |
|
| 162 |
+ runCmd := exec.Command(dockerBinary, "rmi", "") |
|
| 163 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 158 | 164 |
|
| 165 |
+ if err == nil {
|
|
| 166 |
+ t.Fatal("Should have failed to delete '' image")
|
|
| 167 |
+ } |
|
| 168 |
+ |
|
| 169 |
+ if strings.Contains(out, "No such image") {
|
|
| 170 |
+ t.Fatalf("Wrong error message generated: %s", out)
|
|
| 171 |
+ } |
|
| 172 |
+ logDone("rmi- blank image name")
|
|
| 159 | 173 |
} |