-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: skip unix socket tests for non *nix OSes (#1443)
* tests: fix unix socket tests on darwin * tests: add test temp dir implementation for darwin and non darwin
- Loading branch information
Showing
3 changed files
with
141 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//go:build !darwin | ||
|
||
package dns | ||
|
||
import ( | ||
"path/filepath" | ||
"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. | ||
func tempFile(t *testing.T, filename string) string { | ||
t.Helper() | ||
|
||
return filepath.Join(t.TempDir(), filename) | ||
} |