From 95b92b1f979c9c965f171e1763b6e6dc7397006e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Aug 2023 20:00:58 +0200 Subject: [PATCH] api/types: move ResizeOptions to api/types/container Signed-off-by: Sebastiaan van Stijn --- api/types/client.go | 8 -------- api/types/container/options.go | 9 +++++++++ api/types/types_deprecated.go | 8 ++++++++ client/container_resize.go | 6 +++--- client/container_resize_test.go | 10 +++++----- client/interface.go | 4 ++-- integration-cli/docker_cli_events_test.go | 4 ++-- integration/container/resize_test.go | 6 +++--- 8 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 api/types/container/options.go diff --git a/api/types/client.go b/api/types/client.go index b14bac1115..92a48922a8 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -289,14 +289,6 @@ type ImageSearchOptions struct { Limit int } -// ResizeOptions holds parameters to resize a tty. -// It can be used to resize container ttys and -// exec process ttys too. -type ResizeOptions struct { - Height uint - Width uint -} - // NodeListOptions holds parameters to list nodes with. type NodeListOptions struct { Filters filters.Args diff --git a/api/types/container/options.go b/api/types/container/options.go new file mode 100644 index 0000000000..3a340c130c --- /dev/null +++ b/api/types/container/options.go @@ -0,0 +1,9 @@ +package container + +// ResizeOptions holds parameters to resize a TTY. +// It can be used to resize container TTYs and +// exec process TTYs too. +type ResizeOptions struct { + Height uint + Width uint +} diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index c6463fc96c..88d5bc6637 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -2,6 +2,7 @@ package types import ( "github.com/docker/docker/api/types/checkpoint" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" @@ -91,6 +92,13 @@ type ServiceCreateResponse = swarm.ServiceCreateResponse // Deprecated: use [swarm.ServiceUpdateResponse]. type ServiceUpdateResponse = swarm.ServiceUpdateResponse +// ResizeOptions holds parameters to resize a TTY. +// It can be used to resize container TTYs and +// exec process TTYs too. +// +// Deprecated: use [container.ResizeOptions]. +type ResizeOptions = container.ResizeOptions + // DecodeSecurityOptions decodes a security options string slice to a type safe // [system.SecurityOpt]. // diff --git a/client/container_resize.go b/client/container_resize.go index a9d4c0c79a..5cfd01d479 100644 --- a/client/container_resize.go +++ b/client/container_resize.go @@ -5,16 +5,16 @@ import ( "net/url" "strconv" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // ContainerResize changes the size of the tty for a container. -func (cli *Client) ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error { +func (cli *Client) ContainerResize(ctx context.Context, containerID string, options container.ResizeOptions) error { return cli.resize(ctx, "/containers/"+containerID, options.Height, options.Width) } // ContainerExecResize changes the size of the tty for an exec process running inside a container. -func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error { +func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error { return cli.resize(ctx, "/exec/"+execID, options.Height, options.Width) } diff --git a/client/container_resize_test.go b/client/container_resize_test.go index b6b69b1541..76559ef928 100644 --- a/client/container_resize_test.go +++ b/client/container_resize_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -19,7 +19,7 @@ func TestContainerResizeError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{}) + err := client.ContainerResize(context.Background(), "container_id", container.ResizeOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } @@ -27,7 +27,7 @@ func TestContainerExecResizeError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{}) + err := client.ContainerExecResize(context.Background(), "exec_id", container.ResizeOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } @@ -36,7 +36,7 @@ func TestContainerResize(t *testing.T) { client: newMockClient(resizeTransport("/containers/container_id/resize")), } - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{ + err := client.ContainerResize(context.Background(), "container_id", container.ResizeOptions{ Height: 500, Width: 600, }) @@ -50,7 +50,7 @@ func TestContainerExecResize(t *testing.T) { client: newMockClient(resizeTransport("/exec/exec_id/resize")), } - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{ + err := client.ContainerExecResize(context.Background(), "exec_id", container.ResizeOptions{ Height: 500, Width: 600, }) diff --git a/client/interface.go b/client/interface.go index ffdb0de1e3..4807a7ef69 100644 --- a/client/interface.go +++ b/client/interface.go @@ -53,7 +53,7 @@ type ContainerAPIClient interface { 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) - ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error + ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error ContainerExport(ctx context.Context, container string) (io.ReadCloser, error) ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error) @@ -64,7 +64,7 @@ type ContainerAPIClient interface { ContainerPause(ctx context.Context, container string) error ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error ContainerRename(ctx context.Context, container, newContainerName string) error - ContainerResize(ctx context.Context, container string, options types.ResizeOptions) error + ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error) ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error) diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index b76f609b3d..244a71fa74 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" eventtypes "github.com/docker/docker/api/types/events" "github.com/docker/docker/client" eventstestutils "github.com/docker/docker/daemon/events/testutils" @@ -459,7 +459,7 @@ func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) { assert.NilError(c, err) defer apiClient.Close() - options := types.ResizeOptions{ + options := container.ResizeOptions{ Height: 80, Width: 24, } diff --git a/integration/container/resize_test.go b/integration/container/resize_test.go index 6823b3dba1..7cde6e24cd 100644 --- a/integration/container/resize_test.go +++ b/integration/container/resize_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" "github.com/docker/docker/integration/internal/container" @@ -20,7 +20,7 @@ func TestResize(t *testing.T) { t.Run("success", func(t *testing.T) { cID := container.Run(ctx, t, apiClient, container.WithTty(true)) - err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{ + err := apiClient.ContainerResize(ctx, cID, containertypes.ResizeOptions{ Height: 40, Width: 40, }) @@ -46,7 +46,7 @@ func TestResize(t *testing.T) { t.Run("invalid state", func(t *testing.T) { cID := container.Create(ctx, t, apiClient, container.WithCmd("echo")) - err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{ + err := apiClient.ContainerResize(ctx, cID, containertypes.ResizeOptions{ Height: 40, Width: 40, })