forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket.go
32 lines (26 loc) · 778 Bytes
/
socket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 := filepath.Join("/tmp", "sock")
tb.Cleanup(func() {
require.NoError(tb, os.RemoveAll(sock))
})
return sock
}
return filepath.Join(tb.TempDir(), "sock")
}