Skip to content

Commit 99b806c

Browse files
committed
Fix whitespace-insensitive hooks test on Windows
1 parent 27dd35b commit 99b806c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/hooks/installer_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hooks
22

33
import (
4+
"encoding/json"
45
"os"
56
"path/filepath"
67
"runtime"
@@ -230,8 +231,16 @@ func TestSyncForRole_JSONWhitespaceInsensitive(t *testing.T) {
230231
t.Fatalf("reading created file: %v", err)
231232
}
232233

233-
// Add extra whitespace — structurally identical JSON, different bytes
234-
reformatted := strings.ReplaceAll(string(original), ":", " : ")
234+
// Reformat with different whitespace while preserving valid JSON.
235+
var doc any
236+
if err := json.Unmarshal(original, &doc); err != nil {
237+
t.Fatalf("unmarshal original JSON: %v", err)
238+
}
239+
reformattedBytes, err := json.MarshalIndent(doc, "", " ")
240+
if err != nil {
241+
t.Fatalf("marshal reformatted JSON: %v", err)
242+
}
243+
reformatted := string(reformattedBytes) + "\n"
235244
if string(original) == reformatted {
236245
t.Fatal("reformatted content should differ from original bytes")
237246
}

0 commit comments

Comments
 (0)