forked from jefferai/dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmpdir_darwin_test.go
29 lines (24 loc) · 807 Bytes
/
tmpdir_darwin_test.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
//go:build darwin
package dns
import (
"os"
"path/filepath"
"strings"
"testing"
)
// tempDir creates a temporary directory for tests and returns a file path as
// a result of concatenation of said temporary directory path and provided filename.
// The reason for this is to work around some limitations in socket file name
// lengths on darwin.
//
// Ref:
// - https://github.com/golang/go/blob/go1.20.2/src/syscall/ztypes_darwin_arm64.go#L178
// - https://github.com/golang/go/blob/go1.20.2/src/syscall/ztypes_linux_arm64.go#L175
func tempFile(t *testing.T, filename string) string {
t.Helper()
dir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), string(filepath.Separator), "-"))
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
return filepath.Join(dir, filename)
}