hscontrol: keep golden file names valid in Go module zips

A '>' in one name stopped go get from fetching headscale.
This commit is contained in:
Kristoffer Dalby committed 2026-10-29 14:00:02 +01:00
1 parent 0dd9079d0b
commit 46e374aa78
2 files changed
+10 -1

No files matched your search

+10 -1
View File
@@ -13,6 +13,7 @@ import (
"strings"
"testing"
"time"
"unicode"
apiv1 "github.com/juanfont/headscale/hscontrol/api/v1"
"github.com/stretchr/testify/assert"
@@ -142,7 +143,15 @@ type goldenRecord struct {
func goldenPath(t *testing.T) string {
t.Helper()
name := strings.NewReplacer("/", "_", " ", "_").Replace(t.Name())
// Go module zips refuse names with characters such as '>', and one
// such file stops go get from fetching headscale.
name := strings.Map(func(r rune) rune {
if r == '-' || r == '.' || unicode.IsLetter(r) || unicode.IsDigit(r) {
return r
}
return '_'
}, t.Name())
return filepath.Join(goldenDir, name+".json")
}