Skip to content

Commit e571498

Browse files
Fix Windows test failures
- Add sanitizeTestName() to handle Windows-invalid path characters (colons) - Skip Unix executable permission checks on Windows (Windows uses file extensions) - TestBuildConstraintAnalysis: Use sanitized directory names - TestHookManager_InstallHook: Only check executable bit on Unix platforms All tests now pass on Windows, macOS, and Linux.
1 parent 14251c1 commit e571498

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

internal/sbom/enhancer_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ import (
1111
"github.com/go-nv/goenv/internal/manager"
1212
)
1313

14+
// sanitizeTestName replaces characters invalid in Windows paths
15+
func sanitizeTestName(name string) string {
16+
replacer := strings.NewReplacer(
17+
":", "_",
18+
"<", "_",
19+
">", "_",
20+
"\"", "_",
21+
"/", "_",
22+
"\\", "_",
23+
"|", "_",
24+
"?", "_",
25+
"*", "_",
26+
)
27+
return replacer.Replace(name)
28+
}
29+
1430
func TestComputeSBOMDigest(t *testing.T) {
1531
tempDir := t.TempDir()
1632
sbomPath := filepath.Join(tempDir, "sbom.json")
@@ -268,7 +284,7 @@ func TestBuildConstraintAnalysis(t *testing.T) {
268284

269285
for _, tt := range tests {
270286
t.Run(tt.name, func(t *testing.T) {
271-
testDir := filepath.Join(tempDir, tt.name)
287+
testDir := filepath.Join(tempDir, sanitizeTestName(tt.name))
272288
os.MkdirAll(testDir, 0755)
273289

274290
if err := os.WriteFile(filepath.Join(testDir, tt.filename), []byte(tt.content), 0644); err != nil {

internal/sbom/hooks_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7+
"runtime"
78
"strings"
89
"testing"
910
)
@@ -128,14 +129,16 @@ func TestHookManager_InstallHook(t *testing.T) {
128129
return
129130
}
130131

131-
// Verify hook is executable
132-
info, err := os.Stat(hookPath)
133-
if err != nil {
134-
t.Errorf("failed to stat hook: %v", err)
135-
return
136-
}
137-
if info.Mode()&0111 == 0 {
138-
t.Error("hook is not executable")
132+
// Verify hook is executable (Unix only - Windows uses extensions)
133+
if runtime.GOOS != "windows" {
134+
info, err := os.Stat(hookPath)
135+
if err != nil {
136+
t.Errorf("failed to stat hook: %v", err)
137+
return
138+
}
139+
if info.Mode()&0111 == 0 {
140+
t.Error("hook is not executable")
141+
}
139142
}
140143

141144
// Verify hook content

0 commit comments

Comments
 (0)