| 1 | //go:build darwin |
| 2 | |
| 3 | package dns |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "path/filepath" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | // tempDir creates a temporary directory for tests and returns a file path as |
| 13 | // a result of concatenation of said temporary directory path and provided filename. |
| 14 | // The reason for this is to work around some limitations in socket file name |
| 15 | // lengths on darwin. |
| 16 | // |
| 17 | // Ref: |
| 18 | // - https://github.com/golang/go/blob/go1.20.2/src/syscall/ztypes_darwin_arm64.go#L178 |
| 19 | // - https://github.com/golang/go/blob/go1.20.2/src/syscall/ztypes_linux_arm64.go#L175 |
| 20 | func tempFile(t *testing.T, filename string) string { |
| 21 | t.Helper() |
| 22 | |
| 23 | dir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), string(filepath.Separator), "-")) |
| 24 | if err != nil { |
| 25 | t.Fatalf("failed to create temp dir: %v", err) |
| 26 | } |
| 27 | |
| 28 | return filepath.Join(dir, filename) |
| 29 | } |