Skip to content

Commit

Permalink
test: preserve file name when accessing windows fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 24, 2023
1 parent 04f93ce commit a2c1602
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/testutility/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func determineWindowsFixturePath(t *testing.T, path string) string {
return strings.TrimSuffix(path, ext) + "_windows" + ext
}

func loadFixture(t *testing.T, path string) []byte {
func loadFixture(t *testing.T, path string) ([]byte, string) {
t.Helper()

var file []byte
Expand All @@ -39,7 +39,7 @@ func loadFixture(t *testing.T, path string) []byte {
file, err = os.ReadFile(winFixturePath)

if err == nil {
return file
return file, winFixturePath
}
// load the original file if a Windows-specific version does not exist
if !os.IsNotExist(err) {
Expand All @@ -53,14 +53,14 @@ func loadFixture(t *testing.T, path string) []byte {
t.Fatalf("Failed to open fixture: %s", err)
}

return file
return file, path
}

// LoadJSONFixture loads a JSON fixture file and returns the decoded version.
func LoadJSONFixture[V any](t *testing.T, path string) V {
t.Helper()

file := loadFixture(t, path)
file, _ := loadFixture(t, path)

var elem V
err := json.Unmarshal(file, &elem)
Expand Down Expand Up @@ -122,8 +122,10 @@ func normalizeNewlines(content string) string {
func AssertMatchFixtureText(t *testing.T, path string, actual string) {
t.Helper()

fileA, path := loadFixture(t, path)

actual = normalizeNewlines(actual)
expect := string(loadFixture(t, path))
expect := string(fileA)
expect = normalizeNewlines(expect)
if actual != expect {
if os.Getenv("TEST_NO_DIFF") == "true" {
Expand Down

0 comments on commit a2c1602

Please sign in to comment.