MCPcopy
hub / github.com/docker/compose / TestRunHook_ConsoleSize

Function TestRunHook_ConsoleSize

pkg/compose/hook_test.go:42–116  ·  pkg/compose/hook_test.go::TestRunHook_ConsoleSize

TestRunHook_ConsoleSize verifies that ConsoleSize is only passed to ExecAttach when the service has TTY enabled. When TTY is disabled, passing a non-zero ConsoleSize causes the Docker daemon to return "console size is only supported when TTY is enabled" (regression introduced in v5.1.0).

(t *testing.T)

Source from the content-addressed store, hash-verified

40// ConsoleSize causes the Docker daemon to return "console size is only supported
41// when TTY is enabled" (regression introduced in v5.1.0).
42func TestRunHook_ConsoleSize(t *testing.T) {
43 tests := []struct {
44 name string
45 tty bool
46 expectedConsole client.ConsoleSize
47 }{
48 {
49 name: "no tty - ConsoleSize must be zero",
50 tty: false,
51 expectedConsole: client.ConsoleSize{},
52 },
53 {
54 name: "with tty - ConsoleSize should reflect terminal dimensions",
55 tty: true,
56 expectedConsole: client.ConsoleSize{Width: 80, Height: 24},
57 },
58 }
59
60 for _, tc := range tests {
61 t.Run(tc.name, func(t *testing.T) {
62 mockCtrl := gomock.NewController(t)
63 defer mockCtrl.Finish()
64
65 mockAPI := mocks.NewMockAPIClient(mockCtrl)
66 mockCli := mocks.NewMockCli(mockCtrl)
67 mockCli.EXPECT().Client().Return(mockAPI).AnyTimes()
68 mockCli.EXPECT().Err().Return(streams.NewOut(os.Stderr)).AnyTimes()
69
70 // Create a PTY so GetTtySize() returns real non-zero dimensions,
71 // simulating an interactive terminal session.
72 ptmx, tty, err := pty.Open()
73 assert.NilError(t, err)
74 t.Cleanup(func() {
75 _ = ptmx.Close()
76 _ = tty.Close()
77 })
78 assert.NilError(t, pty.Setsize(ptmx, &pty.Winsize{Rows: 24, Cols: 80}))
79 mockCli.EXPECT().Out().Return(streams.NewOut(tty)).AnyTimes()
80
81 service := types.ServiceConfig{
82 Name: "test",
83 Tty: tc.tty,
84 }
85 hook := types.ServiceHook{Command: []string{"echo", "hello"}}
86 ctr := container.Summary{ID: "container123"}
87
88 mockAPI.EXPECT().
89 ExecCreate(gomock.Any(), "container123", gomock.Any()).
90 Return(client.ExecCreateResult{ID: "exec123"}, nil)
91
92 // Return a pipe that immediately closes so the reader gets EOF.
93 serverConn, clientConn := net.Pipe()
94 serverConn.Close() //nolint:errcheck
95 mockAPI.EXPECT().
96 ExecAttach(gomock.Any(), "exec123", client.ExecAttachOptions{
97 TTY: tc.tty,
98 ConsoleSize: tc.expectedConsole,
99 }).

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewMockAPIClientFunction · 0.92
NewMockCliFunction · 0.92
NewComposeServiceFunction · 0.85
runHookMethod · 0.80
ErrMethod · 0.65
CloseMethod · 0.65
ClientMethod · 0.45
OutMethod · 0.45
ExecCreateMethod · 0.45
ExecAttachMethod · 0.45

Tested by

no test coverage detected