diff options
author | Sebastiaan van Stijn <thaJeztah@users.noreply.github.com> | 2023-05-04 19:48:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 19:48:40 +0200 |
commit | 8a4b095a94d57288ab5be58d2abdb7b84309b508 (patch) | |
tree | 291a31c23ff77922da31646630e962899c4d30f2 /client | |
parent | 0e8eea5a70ffce61f391ec9e9bc8324e6e42ff49 (diff) | |
parent | 66cf0e3f5575cace57219607d042cc1c4cd536d2 (diff) | |
download | docker-8a4b095a94d57288ab5be58d2abdb7b84309b508.tar.gz |
Merge pull request #45353 from thaJeztah/api_container_change_type
api/types/container: create type for changes endpoint
Diffstat (limited to 'client')
-rw-r--r-- | client/container_diff.go | 4 | ||||
-rw-r--r-- | client/container_diff_test.go | 45 | ||||
-rw-r--r-- | client/interface.go | 2 |
3 files changed, 27 insertions, 24 deletions
diff --git a/client/container_diff.go b/client/container_diff.go index 29dac8491d..c22c819a79 100644 --- a/client/container_diff.go +++ b/client/container_diff.go @@ -9,8 +9,8 @@ import ( ) // ContainerDiff shows differences in a container filesystem since it was started. -func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.ContainerChangeResponseItem, error) { - var changes []container.ContainerChangeResponseItem +func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) { + var changes []container.FilesystemChange serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil) defer ensureReaderClosed(serverResp) diff --git a/client/container_diff_test.go b/client/container_diff_test.go index 14e243343e..6fad8767b2 100644 --- a/client/container_diff_test.go +++ b/client/container_diff_test.go @@ -12,6 +12,8 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" + "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) func TestContainerDiffError(t *testing.T) { @@ -19,28 +21,33 @@ func TestContainerDiffError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } _, err := client.ContainerDiff(context.Background(), "nothing") - if !errdefs.IsSystem(err) { - t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err) - } + assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } func TestContainerDiff(t *testing.T) { - expectedURL := "/containers/container_id/changes" + const expectedURL = "/containers/container_id/changes" + + expected := []container.FilesystemChange{ + { + Kind: container.ChangeModify, + Path: "/path/1", + }, + { + Kind: container.ChangeAdd, + Path: "/path/2", + }, + { + Kind: container.ChangeDelete, + Path: "/path/3", + }, + } + client := &Client{ client: newMockClient(func(req *http.Request) (*http.Response, error) { if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) + return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal([]container.ContainerChangeResponseItem{ - { - Kind: 0, - Path: "/path/1", - }, - { - Kind: 1, - Path: "/path/2", - }, - }) + b, err := json.Marshal(expected) if err != nil { return nil, err } @@ -52,10 +59,6 @@ func TestContainerDiff(t *testing.T) { } changes, err := client.ContainerDiff(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if len(changes) != 2 { - t.Fatalf("expected an array of 2 changes, got %v", changes) - } + assert.Check(t, err) + assert.Check(t, is.DeepEqual(changes, expected)) } diff --git a/client/interface.go b/client/interface.go index 692dcfbece..64877d1641 100644 --- a/client/interface.go +++ b/client/interface.go @@ -48,7 +48,7 @@ type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.CreateResponse, error) - ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error) + ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) |