(t *testing.T)
| 67 | } |
| 68 | |
| 69 | func TestRunAttach(t *testing.T) { |
| 70 | p, tty, err := pty.Open() |
| 71 | assert.NilError(t, err) |
| 72 | defer func() { |
| 73 | _ = tty.Close() |
| 74 | _ = p.Close() |
| 75 | }() |
| 76 | |
| 77 | var conn net.Conn |
| 78 | attachCh := make(chan struct{}) |
| 79 | fakeCLI := test.NewFakeCli(&fakeClient{ |
| 80 | createContainerFunc: func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error) { |
| 81 | return client.ContainerCreateResult{ID: "id"}, nil |
| 82 | }, |
| 83 | containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) { |
| 84 | server, clientConn := net.Pipe() |
| 85 | conn = server |
| 86 | t.Cleanup(func() { |
| 87 | _ = server.Close() |
| 88 | }) |
| 89 | attachCh <- struct{}{} |
| 90 | return client.ContainerAttachResult{ |
| 91 | HijackedResponse: client.NewHijackedResponse(clientConn, types.MediaTypeRawStream), |
| 92 | }, nil |
| 93 | }, |
| 94 | waitFunc: func(_ string) client.ContainerWaitResult { |
| 95 | responseChan := make(chan container.WaitResponse, 1) |
| 96 | errChan := make(chan error) |
| 97 | |
| 98 | responseChan <- container.WaitResponse{ |
| 99 | StatusCode: 33, |
| 100 | } |
| 101 | return client.ContainerWaitResult{ |
| 102 | Result: responseChan, |
| 103 | Error: errChan, |
| 104 | } |
| 105 | }, |
| 106 | // use new (non-legacy) wait API |
| 107 | // see: https://github.com/docker/cli/commit/38591f20d07795aaef45d400df89ca12f29c603b |
| 108 | Version: client.MaxAPIVersion, |
| 109 | }, func(fc *test.FakeCli) { |
| 110 | fc.SetOut(streams.NewOut(tty)) |
| 111 | fc.SetIn(streams.NewIn(tty)) |
| 112 | }) |
| 113 | |
| 114 | cmd := newRunCommand(fakeCLI) |
| 115 | cmd.SetArgs([]string{"-it", "busybox"}) |
| 116 | cmd.SilenceUsage = true |
| 117 | cmdErrC := make(chan error, 1) |
| 118 | go func() { |
| 119 | cmdErrC <- cmd.Execute() |
| 120 | }() |
| 121 | |
| 122 | // run command should attempt to attach to the container |
| 123 | select { |
| 124 | case <-time.After(5 * time.Second): |
| 125 | t.Fatal("containerAttachFunc was not called before the 5 second timeout") |
| 126 | case <-attachCh: |
nothing calls this directly
no test coverage detected
searching dependent graphs…