11 "github.com/stretchr/testify/require"
14 // TerminalTestClient is a terminal client of a test daemon, with a pipe as its
16 type TerminalTestClient struct {
22 // Type writes one line to the input of the client.
23 func (c *TerminalTestClient) Type(line string) {
24 _, err := io.WriteString(c.input, line+"\n")
30 // Output returns what the client showed.
31 func (c *TerminalTestClient) Output() string {
35 // WaitFor waits until the client showed text.
36 func (c *TerminalTestClient) WaitFor(t *testing.T, text string) {
39 require.Eventually(t, func() bool {
40 return strings.Contains(c.Output(), text)
41 }, 10*time.Second, time.Millisecond, "output so far: %q", c.Output())
44 // Close ends the input and waits for the client.
45 func (c *TerminalTestClient) Close() error {
46 err := c.input.Close()
48 return fmt.Errorf("close terminal input: %w", err)
54 // terminalStartTestClient connects a client to the daemon at socket.
55 func terminalStartTestClient(t *testing.T, socket string) *TerminalTestClient {
58 conn, err := net.Dial("unix", socket)
59 require.NoError(t, err)
61 reader, writer := io.Pipe()
62 client := &TerminalTestClient{
64 done: make(chan error, 1),
69 client.done <- terminalSession(t.Context(), conn, reader, client.out)