Ver código fonte

Merge pull request #36000 from emil2k/fix-container-log-err

Wrap response error for container logs method.
Sebastiaan van Stijn 7 anos atrás
pai
commit
6415f1dcf5
2 arquivos alterados com 11 adições e 1 exclusões
  1. 1 1
      client/container_logs.go
  2. 10 0
      client/container_logs_test.go

+ 1 - 1
client/container_logs.go

@@ -74,7 +74,7 @@ func (cli *Client) ContainerLogs(ctx context.Context, container string, options
 
 
 	resp, err := cli.get(ctx, "/containers/"+container+"/logs", query, nil)
 	resp, err := cli.get(ctx, "/containers/"+container+"/logs", query, nil)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return nil, wrapResponseError(err, resp, "container", container)
 	}
 	}
 	return resp.body, nil
 	return resp.body, nil
 }
 }

+ 10 - 0
client/container_logs_test.go

@@ -18,6 +18,16 @@ import (
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
 
 
+func TestContainerLogsNotFoundError(t *testing.T) {
+	client := &Client{
+		client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
+	}
+	_, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{})
+	if !IsErrNotFound(err) {
+		t.Fatalf("expected a not found error, got %v", err)
+	}
+}
+
 func TestContainerLogsError(t *testing.T) {
 func TestContainerLogsError(t *testing.T) {
 	client := &Client{
 	client := &Client{
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),