Close out the repository audit

This commit is contained in:
2026-08-13 13:52:16 +00:00
parent 13b06039b1
commit fc8ddada9a
29 changed files with 421 additions and 263 deletions

View 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)
}

View File

@@ -0,0 +1,7 @@
//go:build !windows
package testutil
func platformSymlinkUnavailable(error) bool {
return false
}

View 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)
}
})
}
}

View 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)
}