10 "github.com/stretchr/testify/require"
13 // TerminalTestClient is a terminal client of a test daemon, with a pipe as its
15 type TerminalTestClient struct {
21 // Type writes one line to the input of the client.
22 func (c *TerminalTestClient) Type(line string) {
23 _, err := io.WriteString(c.input, line+"\n")
29 // Output returns what the client showed.
30 func (c *TerminalTestClient) Output() string {
34 // WaitFor waits until the client showed text.
35 func (c *TerminalTestClient) WaitFor(t *testing.T, text string) {
38 require.Eventually(t, func() bool {
39 return strings.Contains(c.Output(), text)
40 }, 10*time.Second, time.Millisecond, "output so far: %q", c.Output())
43 // Close ends the input and waits for the client.
44 func (c *TerminalTestClient) Close() error {
45 err := c.input.Close()
53 // terminalStartTestClient connects a client to the daemon at socket.
54 func terminalStartTestClient(t *testing.T, socket string) *TerminalTestClient {
57 conn, err := net.Dial("unix", socket)
58 require.NoError(t, err)
60 reader, writer := io.Pipe()
61 client := &TerminalTestClient{
63 done: make(chan error, 1),
68 client.done <- terminalSession(t.Context(), conn, reader, client.out)