]> git.giacomolli.uk - onechat/blobdiff - daemon_start_helper_test.go
Queue external data for the next root turn
[onechat] / daemon_start_helper_test.go
index 81399ce3ca3c3548d815bd52294723e58863d6c3..a27967ea62ab81909e23aee2c4b02a4d3bbfa0e0 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "context"
+       "os"
        "path/filepath"
        "testing"
        "time"
@@ -35,7 +36,7 @@ func daemonStartTestWithWhatsApp(t *testing.T, server *ModelFake, bot *TelegramB
 func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *TelegramBot, whatsapp *WhatsApp, schedules *Schedules, clock func() time.Time) (string, *Memory) {
        t.Helper()
 
-       dir := t.TempDir()
+       dir := daemonTestSocketDir(t)
        agent, err := openAgent(filepath.Join(dir, daemonAgentDirName))
        require.NoError(t, err)
 
@@ -65,3 +66,19 @@ func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *Telegram
 
        return socket, memory
 }
+
+// daemonTestSocketDir returns a new short directory under /tmp for data that
+// holds a daemon socket. t.TempDir holds the test name and the TMPDIR of the
+// shell, so its paths can pass the 107-byte limit of a Unix socket path.
+func daemonTestSocketDir(t *testing.T) string {
+       t.Helper()
+
+       dir, err := os.MkdirTemp("/tmp", "onechat-")
+       require.NoError(t, err)
+
+       t.Cleanup(func() {
+               require.NoError(t, os.RemoveAll(dir))
+       })
+
+       return dir
+}