1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

client should return imageNotFound error when API returns 404 status code

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
Arash Deshmeh 2017-08-15 17:16:02 -04:00
parent cd902848e9
commit 33d82b78d0
2 changed files with 15 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"net/http"
"net/url" "net/url"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
@ -21,6 +22,9 @@ func (cli *Client) ImageRemove(ctx context.Context, imageID string, options type
resp, err := cli.delete(ctx, "/images/"+imageID, query, nil) resp, err := cli.delete(ctx, "/images/"+imageID, query, nil)
if err != nil { if err != nil {
if resp.statusCode == http.StatusNotFound {
return nil, imageNotFoundError{imageID}
}
return nil, err return nil, err
} }

View file

@ -24,6 +24,17 @@ func TestImageRemoveError(t *testing.T) {
} }
} }
func TestImageRemoveImageNotFound(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
}
_, err := client.ImageRemove(context.Background(), "unknown", types.ImageRemoveOptions{})
if err == nil || !IsErrNotFound(err) {
t.Fatalf("expected an imageNotFoundError error, got %v", err)
}
}
func TestImageRemove(t *testing.T) { func TestImageRemove(t *testing.T) {
expectedURL := "/images/image_id" expectedURL := "/images/image_id"
removeCases := []struct { removeCases := []struct {