MCPcopy Index your code
hub / github.com/coder/coder / TempDirUnixSocket

Function TempDirUnixSocket

testutil/unixsocket.go:25–42  ·  view source on GitHub ↗

TempDirUnixSocket returns a temporary directory that can safely hold unix sockets (probably). During tests on darwin we hit the max path length limit for unix sockets pretty easily in the default location, so this function uses /tmp instead to get shorter paths. On Linux, we also hit this limit on

(t testing.TB)

Source from the content-addressed store, hash-verified

23// On Linux, we also hit this limit on GitHub Actions runners where TMPDIR is
24// set to a long path like /home/runner/work/_temp/go-tmp/.
25func TempDirUnixSocket(t testing.TB) string {
26 t.Helper()
27 // Windows doesn't have the same unix socket path length limits,
28 // and callers of this function are generally gated to !windows.
29 if runtime.GOOS == "windows" {
30 return t.TempDir()
31 }
32
33 testName := strings.ReplaceAll(t.Name(), "/", "_")
34 dir, err := os.MkdirTemp("/tmp", testName)
35 require.NoError(t, err, "create temp dir for unix socket test")
36
37 t.Cleanup(func() {
38 err := os.RemoveAll(dir)
39 assert.NoError(t, err, "remove temp dir", dir)
40 })
41 return dir
42}
43
44func AgentSocketPath(t testing.TB) string {
45 if runtime.GOOS == "windows" {

Calls 5

RemoveAllMethod · 0.80
HelperMethod · 0.65
TempDirMethod · 0.65
NameMethod · 0.65
CleanupMethod · 0.65