]> git.giacomolli.uk - onechat/blobdiff - daemon_test.go
Call the Telegram Bot API
[onechat] / daemon_test.go
index 91d6ecc8658095f12c6be089e2b229ab7db83889..00680e6fec697e028bdeeadf25688f698257b3fc 100644 (file)
@@ -116,6 +116,18 @@ func TestListenSocketRefusesALongPath(t *testing.T) {
        require.ErrorContains(t, err, "set ONECHAT_DIR to a shorter path")
 }
 
+func TestDaemonWritesNoFileForALongSocketPath(t *testing.T) {
+       dir := filepath.Join(t.TempDir(), strings.Repeat("d", 100))
+       t.Setenv("ONECHAT_DIR", dir)
+
+       err := daemon(t.Context(), io.Discard)
+       require.ErrorContains(t, err, "set ONECHAT_DIR to a shorter path")
+
+       entries, err := os.ReadDir(dir)
+       require.NoError(t, err)
+       require.Empty(t, entries)
+}
+
 func TestOneProcessHoldsTheTokens(t *testing.T) {
        dir := t.TempDir()
        lock, err := lockTokens(dir)
@@ -142,10 +154,15 @@ func TestEventText(t *testing.T) {
                        text:  "Done.",
                },
                {
-                       name:  "user message not shown",
-                       event: Event{Kind: "user", Text: "typed"},
+                       name:  "own user message not shown",
+                       event: Event{Kind: "user", Text: "typed", Source: terminalSource},
                        text:  "",
                },
+               {
+                       name:  "user message of another source marked",
+                       event: Event{Kind: "user", Text: "from the phone", Source: "telegram"},
+                       text:  "[telegram] from the phone",
+               },
                {
                        name:  "long result cut",
                        event: Event{Kind: "echo", Text: strings.Repeat("line\n", 12)},