1
0
Fork 0
telegraf/testutil/socket.go
Daniel Baumann 4978089aab
Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-05-24 07:26:29 +02:00

32 lines
760 B
Go

package testutil
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/require"
)
func TempSocket(tb testing.TB) string {
// On MacOS, the maximum path length of Unix domain socket is 104
// characters. (https://unix.stackexchange.com/a/367012/376279)
//
// On MacOS, tb.TempDir() returns e.g.
// /var/folders/bl/wbxjgtzx7j5_mjsmfr3ynlc00000gp/T/<the-test-name>/001/socket.sock
//
// If the name of the test is long, the path length could exceed 104
// characters, and this would result in listen unix ...: bind: invalid argument
if runtime.GOOS == "darwin" {
sock := "/tmp/sock"
tb.Cleanup(func() {
require.NoError(tb, os.RemoveAll(sock))
})
return sock
}
return filepath.Join(tb.TempDir(), "sock")
}