MCPcopy
hub / github.com/moby/moby / TestAttach

Function TestAttach

integration/container/attach_test.go:20–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestAttach(t *testing.T) {
21 ctx := setupTest(t)
22 apiClient := testEnv.APIClient()
23
24 tests := []struct {
25 doc string
26 tty bool
27 expectedMediaType string
28 }{
29 {
30 doc: "without TTY",
31 expectedMediaType: types.MediaTypeMultiplexedStream,
32 },
33 {
34 doc: "with TTY",
35 tty: true,
36 expectedMediaType: types.MediaTypeRawStream,
37 },
38 }
39 for _, tc := range tests {
40 t.Run(tc.doc, func(t *testing.T) {
41 t.Parallel()
42
43 ctx := testutil.StartSpan(ctx, t)
44 resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{
45 Config: &container.Config{
46 Image: "busybox",
47 Cmd: []string{"echo", "hello"},
48 Tty: tc.tty,
49 },
50 HostConfig: &container.HostConfig{},
51 NetworkingConfig: &network.NetworkingConfig{},
52 })
53 assert.NilError(t, err)
54 attach, err := apiClient.ContainerAttach(ctx, resp.ID, client.ContainerAttachOptions{
55 Stdout: true,
56 Stderr: true,
57 })
58 assert.NilError(t, err)
59 mediaType, ok := attach.MediaType()
60 assert.Check(t, ok)
61 assert.Check(t, is.Equal(mediaType, tc.expectedMediaType))
62 })
63 }
64}
65
66// Regression test for #37182
67func TestAttachDisconnectLeak(t *testing.T) {

Callers

nothing calls this directly

Calls 9

StartSpanFunction · 0.92
APIClientMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
RunMethod · 0.65
ContainerCreateMethod · 0.65
ContainerAttachMethod · 0.65
MediaTypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…