From: Anderson A. Giacomolli Date: Tue, 10 Nov 2026 19:27:23 +0000 (-0300) Subject: Keep test daemon sockets under the path limit X-Git-Url: https://git.giacomolli.uk/onechat/commitdiff_plain/195c3fbb075383ac47bba310eb701b02774e8d10?ds=sidebyside;hp=b1be0ee8530df5db8973bfe355f2f6d3149383a0 Keep test daemon sockets under the path limit 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. --- diff --git a/daemon_start_helper_test.go b/daemon_start_helper_test.go index 81399ce..c43ff9c 100644 --- a/daemon_start_helper_test.go +++ b/daemon_start_helper_test.go @@ -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 index 0000000..44177bd --- /dev/null +++ b/socket_helper_test.go @@ -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 +}