MCPcopy Index your code
hub / github.com/docker/cli / TestRunAttachTermination

Function TestRunAttachTermination

cli/command/container/run_test.go:142–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func TestRunAttachTermination(t *testing.T) {
143 p, tty, err := pty.Open()
144 assert.NilError(t, err)
145 defer func() {
146 _ = tty.Close()
147 _ = p.Close()
148 }()
149
150 var conn net.Conn
151 killCh := make(chan struct{})
152 attachCh := make(chan struct{})
153 fakeCLI := test.NewFakeCli(&fakeClient{
154 createContainerFunc: func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error) {
155 return client.ContainerCreateResult{ID: "id"}, nil
156 },
157 containerKillFunc: func(ctx context.Context, container string, options client.ContainerKillOptions) (client.ContainerKillResult, error) {
158 if options.Signal == "TERM" {
159 close(killCh)
160 }
161 return client.ContainerKillResult{}, nil
162 },
163 containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) {
164 server, clientConn := net.Pipe()
165 conn = server
166 t.Cleanup(func() {
167 _ = server.Close()
168 })
169 attachCh <- struct{}{}
170 return client.ContainerAttachResult{
171 HijackedResponse: client.NewHijackedResponse(clientConn, types.MediaTypeRawStream),
172 }, nil
173 },
174 waitFunc: func(_ string) client.ContainerWaitResult {
175 responseChan := make(chan container.WaitResponse, 1)
176 errChan := make(chan error)
177 <-killCh
178 responseChan <- container.WaitResponse{
179 StatusCode: 130,
180 }
181 return client.ContainerWaitResult{
182 Result: responseChan,
183 Error: errChan,
184 }
185 },
186 // use new (non-legacy) wait API
187 // see: https://github.com/docker/cli/commit/38591f20d07795aaef45d400df89ca12f29c603b
188 Version: client.MaxAPIVersion,
189 }, func(fc *test.FakeCli) {
190 fc.SetOut(streams.NewOut(tty))
191 fc.SetIn(streams.NewIn(tty))
192 })
193
194 cmd := newRunCommand(fakeCLI)
195 cmd.SetArgs([]string{"-it", "busybox"})
196 cmd.SilenceUsage = true
197 cmdErrC := make(chan error, 1)
198 go func() {
199 cmdErrC <- cmd.Execute()

Callers

nothing calls this directly

Calls 5

newRunCommandFunction · 0.85
SetArgsMethod · 0.80
SetInMethod · 0.65
CloseMethod · 0.45
SetOutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…