27 lines
784 B
Go
27 lines
784 B
Go
// 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)
|
|
}
|