Browse code

api/types: move ContainerAttachOptions to api/types/container

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/08/26 03:10:15
Showing 10 changed files
... ...
@@ -11,16 +11,6 @@ import (
11 11
 	units "github.com/docker/go-units"
12 12
 )
13 13
 
14
-// ContainerAttachOptions holds parameters to attach to a container.
15
-type ContainerAttachOptions struct {
16
-	Stream     bool
17
-	Stdin      bool
18
-	Stdout     bool
19
-	Stderr     bool
20
-	DetachKeys string
21
-	Logs       bool
22
-}
23
-
24 14
 // ContainerCommitOptions holds parameters to commit changes into a container.
25 15
 type ContainerCommitOptions struct {
26 16
 	Reference string
... ...
@@ -7,3 +7,13 @@ type ResizeOptions struct {
7 7
 	Height uint
8 8
 	Width  uint
9 9
 }
10
+
11
+// AttachOptions holds parameters to attach to a container.
12
+type AttachOptions struct {
13
+	Stream     bool
14
+	Stdin      bool
15
+	Stdout     bool
16
+	Stderr     bool
17
+	DetachKeys string
18
+	Logs       bool
19
+}
... ...
@@ -99,6 +99,11 @@ type ServiceUpdateResponse = swarm.ServiceUpdateResponse
99 99
 // Deprecated: use [container.ResizeOptions].
100 100
 type ResizeOptions = container.ResizeOptions
101 101
 
102
+// ContainerAttachOptions holds parameters to attach to a container.
103
+//
104
+// Deprecated: use [container.AttachOptions].
105
+type ContainerAttachOptions = container.AttachOptions
106
+
102 107
 // DecodeSecurityOptions decodes a security options string slice to a type safe
103 108
 // [system.SecurityOpt].
104 109
 //
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"net/url"
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/api/types/container"
9 10
 )
10 11
 
11 12
 // ContainerAttach attaches a connection to a container in the server.
... ...
@@ -32,7 +33,7 @@ import (
32 32
 //
33 33
 // You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this
34 34
 // stream.
35
-func (cli *Client) ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) {
35
+func (cli *Client) ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error) {
36 36
 	query := url.Values{}
37 37
 	if options.Stream {
38 38
 		query.Set("stream", "1")
... ...
@@ -46,7 +46,7 @@ type CommonAPIClient interface {
46 46
 
47 47
 // ContainerAPIClient defines API client methods for the containers
48 48
 type ContainerAPIClient interface {
49
-	ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
49
+	ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error)
50 50
 	ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error)
51 51
 	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
52 52
 	ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14
+	"github.com/docker/docker/api/types/container"
14 15
 	"github.com/docker/docker/client"
15 16
 	"github.com/docker/docker/pkg/stdcopy"
16 17
 	"github.com/docker/docker/testutil"
... ...
@@ -184,7 +185,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
184 184
 	cid = strings.TrimSpace(cid)
185 185
 
186 186
 	// Make sure we don't see "hello" if Logs is false
187
-	attachOpts := types.ContainerAttachOptions{
187
+	attachOpts := container.AttachOptions{
188 188
 		Stream: true,
189 189
 		Stdin:  true,
190 190
 		Stdout: true,
... ...
@@ -13,7 +13,7 @@ import (
13 13
 
14 14
 func TestAttach(t *testing.T) {
15 15
 	ctx := setupTest(t)
16
-	client := testEnv.APIClient()
16
+	apiClient := testEnv.APIClient()
17 17
 
18 18
 	tests := []struct {
19 19
 		doc               string
... ...
@@ -36,7 +36,7 @@ func TestAttach(t *testing.T) {
36 36
 			t.Parallel()
37 37
 
38 38
 			ctx := testutil.StartSpan(ctx, t)
39
-			resp, err := client.ContainerCreate(ctx,
39
+			resp, err := apiClient.ContainerCreate(ctx,
40 40
 				&container.Config{
41 41
 					Image: "busybox",
42 42
 					Cmd:   []string{"echo", "hello"},
... ...
@@ -48,7 +48,7 @@ func TestAttach(t *testing.T) {
48 48
 				"",
49 49
 			)
50 50
 			assert.NilError(t, err)
51
-			attach, err := client.ContainerAttach(ctx, resp.ID, types.ContainerAttachOptions{
51
+			attach, err := apiClient.ContainerAttach(ctx, resp.ID, container.AttachOptions{
52 52
 				Stdout: true,
53 53
 				Stderr: true,
54 54
 			})
... ...
@@ -145,7 +145,7 @@ func TestWaitConditions(t *testing.T) {
145 145
 			containerID := container.Create(ctx, t, cli, opts...)
146 146
 			t.Logf("ContainerID = %v", containerID)
147 147
 
148
-			streams, err := cli.ContainerAttach(ctx, containerID, types.ContainerAttachOptions{Stream: true, Stdin: true})
148
+			streams, err := cli.ContainerAttach(ctx, containerID, containertypes.AttachOptions{Stream: true, Stdin: true})
149 149
 			assert.NilError(t, err)
150 150
 			defer streams.Close()
151 151
 
... ...
@@ -99,7 +99,7 @@ func RunAttach(ctx context.Context, t *testing.T, apiClient client.APIClient, op
99 99
 	})
100 100
 	id := Create(ctx, t, apiClient, ops...)
101 101
 
102
-	aresp, err := apiClient.ContainerAttach(ctx, id, types.ContainerAttachOptions{
102
+	aresp, err := apiClient.ContainerAttach(ctx, id, container.AttachOptions{
103 103
 		Stream: true,
104 104
 		Stdout: true,
105 105
 		Stderr: true,
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"time"
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12
+	containertypes "github.com/docker/docker/api/types/container"
12 13
 	"github.com/docker/docker/integration/internal/container"
13 14
 	"github.com/docker/docker/testutil"
14 15
 	"github.com/docker/docker/testutil/daemon"
... ...
@@ -49,7 +50,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
49 49
 	defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})
50 50
 
51 51
 	// Attach to the container to make sure it's written a few times to stdout
52
-	attach, err := client.ContainerAttach(ctx, id, types.ContainerAttachOptions{Stream: true, Stdout: true})
52
+	attach, err := client.ContainerAttach(ctx, id, containertypes.AttachOptions{Stream: true, Stdout: true})
53 53
 	assert.NilError(t, err)
54 54
 
55 55
 	chErr := make(chan error, 1)