Close out the repository audit
This commit is contained in:
26
internal/testutil/symlink.go
Normal file
26
internal/testutil/symlink.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package testutil contains test-only helpers shared across package suites.
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// RequireSymlink creates a symbolic link or skips when the host explicitly
|
||||
// reports that the operation is unsupported or unavailable to the test user.
|
||||
// Unexpected setup failures remain test failures.
|
||||
func RequireSymlink(t testing.TB, target, link string) {
|
||||
t.Helper()
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
if symlinkUnavailable(err) {
|
||||
t.Skipf("symlink support is unavailable: %v", err)
|
||||
}
|
||||
t.Fatalf("create symlink %q -> %q: %v", link, target, err)
|
||||
}
|
||||
}
|
||||
|
||||
func symlinkUnavailable(err error) bool {
|
||||
return errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported) || platformSymlinkUnavailable(err)
|
||||
}
|
||||
Reference in New Issue
Block a user