MCPcopy Index your code
hub / github.com/coder/coder / Test_Start_copy

Function Test_Start_copy

pty/start_test.go:20–54  ·  view source on GitHub ↗

Test_Start_copy tests that we can use io.Copy() on command output without deadlocking.

(t *testing.T)

Source from the content-addressed store, hash-verified

18// Test_Start_copy tests that we can use io.Copy() on command output
19// without deadlocking.
20func Test_Start_copy(t *testing.T) {
21 t.Parallel()
22
23 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
24 defer cancel()
25
26 pc, cmd, err := pty.Start(pty.CommandContext(ctx, cmdEcho, argEcho...))
27 require.NoError(t, err)
28 b := &bytes.Buffer{}
29 readDone := make(chan error, 1)
30 go func() {
31 _, err := io.Copy(b, pc.OutputReader())
32 readDone <- err
33 }()
34
35 select {
36 case err := <-readDone:
37 require.NoError(t, err)
38 case <-ctx.Done():
39 t.Error("read timed out")
40 }
41 assert.Contains(t, b.String(), "test")
42
43 cmdDone := make(chan error, 1)
44 go func() {
45 cmdDone <- cmd.Wait()
46 }()
47
48 select {
49 case err := <-cmdDone:
50 require.NoError(t, err)
51 case <-ctx.Done():
52 t.Error("cmd.Wait() timed out")
53 }
54}
55
56// Test_Start_truncation tests that we can read command output without truncation
57// even after the command has exited.

Callers

nothing calls this directly

Calls 9

StartFunction · 0.92
CommandContextFunction · 0.92
CopyMethod · 0.65
OutputReaderMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected