From 33d82b78d03f7db4ef743951c6a004ba4fe64637 Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Tue, 15 Aug 2017 17:16:02 -0400 Subject: [PATCH] client should return imageNotFound error when API returns 404 status code Signed-off-by: Arash Deshmeh --- client/image_remove.go | 4 ++++ client/image_remove_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/client/image_remove.go b/client/image_remove.go index 6921209ee1..94e4b74ec3 100644 --- a/client/image_remove.go +++ b/client/image_remove.go @@ -2,6 +2,7 @@ package client import ( "encoding/json" + "net/http" "net/url" "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) if err != nil { + if resp.statusCode == http.StatusNotFound { + return nil, imageNotFoundError{imageID} + } return nil, err } diff --git a/client/image_remove_test.go b/client/image_remove_test.go index 9856311305..5a391b0ae6 100644 --- a/client/image_remove_test.go +++ b/client/image_remove_test.go @@ -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) { expectedURL := "/images/image_id" removeCases := []struct {