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)
|
||||
}
|
||||
7
internal/testutil/symlink_other.go
Normal file
7
internal/testutil/symlink_other.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package testutil
|
||||
|
||||
func platformSymlinkUnavailable(error) bool {
|
||||
return false
|
||||
}
|
||||
25
internal/testutil/symlink_test.go
Normal file
25
internal/testutil/symlink_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSymlinkUnavailableClassifiesOnlyCapabilityErrors(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{name: "permission", err: fs.ErrPermission, want: true},
|
||||
{name: "unsupported", err: errors.ErrUnsupported, want: true},
|
||||
{name: "unexpected", err: errors.New("fixture path is invalid"), want: false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := symlinkUnavailable(test.err); got != test.want {
|
||||
t.Fatalf("symlinkUnavailable(%v) = %t, want %t", test.err, got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
12
internal/testutil/symlink_windows.go
Normal file
12
internal/testutil/symlink_windows.go
Normal file
@@ -0,0 +1,12 @@
|
||||
//go:build windows
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func platformSymlinkUnavailable(err error) bool {
|
||||
return errors.Is(err, syscall.ERROR_PRIVILEGE_NOT_HELD)
|
||||
}
|
||||
Reference in New Issue
Block a user