10 "github.com/stretchr/testify/require"
13 func TestClientEndsWhenTheDaemonEnds(t *testing.T) {
15 listener, err := daemonListenSocket(filepath.Join(dir, socketFileName))
16 require.NoError(t, err)
18 accepted := make(chan net.Conn)
20 conn, err := listener.Accept()
26 conn, err := net.Dial("unix", filepath.Join(dir, socketFileName))
27 require.NoError(t, err)
30 done := make(chan error)
32 done <- terminalSession(t.Context(), conn, in, io.Discard)
35 require.NoError(t, (<-accepted).Close())
36 require.ErrorIs(t, <-done, errTerminalDaemonClosed)
37 require.NoError(t, listener.Close())
40 func TestEventText(t *testing.T) {
41 testCases := []struct {
47 name: "reply as it is",
48 event: Event{Kind: "reply", Text: "Done."},
52 name: "own user message not shown",
53 event: Event{Kind: "user", Text: "typed", Source: terminalSource},
57 name: "user message of another source marked",
58 event: Event{Kind: "user", Text: "from the phone", Source: "telegram"},
59 text: "[telegram] from the phone",
62 name: "long result cut",
63 event: Event{Kind: "echo", Text: strings.Repeat("line\n", 12)},
64 text: "[result] " + strings.Repeat("line\n", 9) + "line\n[2 more lines]",
68 for _, tc := range testCases {
69 t.Run(tc.name, func(t *testing.T) {
70 require.Equal(t, tc.text, terminalEventText(tc.event))