Skip to content

Commit

Permalink
test: fix tests on windows where slash does not matter
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Jun 4, 2024
1 parent 66c08f5 commit 39ac328
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,27 @@ func TestFinder_Find(t *testing.T) {
results, err := tt.finder.Find(fsys)
require.NoError(t, err)

assert.Equal(t, tt.results, results)
assert.Equal(t, tt.results, eachToSlash(results))
})
}
}

// eachToSlash converts all path separators to forward slashes.
// This is useful for testing on Windows.
func eachToSlash(paths []string) []string {
if paths == nil {
return nil
}

newPaths := make([]string, len(paths))

for i, p := range paths {
newPaths[i] = filepath.ToSlash(p)
}

return newPaths
}

func TestFinder_Find_RelativePaths(t *testing.T) {
fsys := afero.NewOsFs()

Expand All @@ -288,7 +304,7 @@ func TestFinder_Find_RelativePaths(t *testing.T) {
"testdata/etc/config.yaml",
}

assert.Equal(t, expected, results)
assert.Equal(t, eachToSlash(expected), results)
}

func TestFinder_Find_AbsolutePaths(t *testing.T) {
Expand Down

0 comments on commit 39ac328

Please sign in to comment.