]> git.giacomolli.uk - onechat/commitdiff
Keep test daemon sockets under the path limit
authorAnderson A. Giacomolli <redacted>
Tue, 10 Nov 2026 19:27:23 +0000 (16:27 -0300)
committerAnderson A. Giacomolli <redacted>
Tue, 10 Nov 2026 19:27:23 +0000 (16:27 -0300)
The test daemon keeps its data, and so its socket, in a short directory
under /tmp. t.TempDir holds the test name and the long TMPDIR of the
development shell, so a test with a long name failed to listen on a
socket path over 107 bytes, and bin/check failed in the shell unless
TMPDIR was set short by hand.

daemon_start_helper_test.go
socket_helper_test.go [new file with mode: 0644]

index 81399ce3ca3c3548d815bd52294723e58863d6c3..c43ff9cb58989ab31141e837388205a835f959a2 100644 (file)
@@ -35,7 +35,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 := socketTestDir(t)
        agent, err := openAgent(filepath.Join(dir, daemonAgentDirName))
        require.NoError(t, err)
 
diff --git a/socket_helper_test.go b/socket_helper_test.go
new file mode 100644 (file)
index 0000000..44177bd
--- /dev/null
@@ -0,0 +1,24 @@
+package main
+
+import (
+       "os"
+       "testing"
+
+       "github.com/stretchr/testify/require"
+)
+
+// socketTestDir 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 socketTestDir(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
+}