瀏覽代碼

Merge pull request #30653 from vipconsult/28766-fix-checkpoint-ls-error-messages

more descriptive error for checkpoint ls  for non existent containers
Vincent Demeester 8 年之前
父節點
當前提交
31f1ff029f
共有 2 個文件被更改,包括 15 次插入0 次删除
  1. 4 0
      client/checkpoint_list.go
  2. 11 0
      client/checkpoint_list_test.go

+ 4 - 0
client/checkpoint_list.go

@@ -2,6 +2,7 @@ package client
 
 import (
 	"encoding/json"
+	"net/http"
 	"net/url"
 
 	"github.com/docker/docker/api/types"
@@ -19,6 +20,9 @@ func (cli *Client) CheckpointList(ctx context.Context, container string, options
 
 	resp, err := cli.get(ctx, "/containers/"+container+"/checkpoints", query, nil)
 	if err != nil {
+		if resp.statusCode == http.StatusNotFound {
+			return checkpoints, containerNotFoundError{container}
+		}
 		return checkpoints, err
 	}
 

+ 11 - 0
client/checkpoint_list_test.go

@@ -55,3 +55,14 @@ func TestCheckpointList(t *testing.T) {
 		t.Fatalf("expected 1 checkpoint, got %v", checkpoints)
 	}
 }
+
+func TestCheckpointListContainerNotFound(t *testing.T) {
+	client := &Client{
+		client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
+	}
+
+	_, err := client.CheckpointList(context.Background(), "unknown", types.CheckpointListOptions{})
+	if err == nil || !IsErrContainerNotFound(err) {
+		t.Fatalf("expected a containerNotFound error, got %v", err)
+	}
+}