Skip to content

Commit

Permalink
Normalize path separator in tests based in OS
Browse files Browse the repository at this point in the history
Use OS specific path separators in tests


This commit was moved from ipfs/go-ipfs-files@ac10fa8
  • Loading branch information
masih committed Jul 22, 2021
1 parent ecef908 commit 302094f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions files/filewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ func TestWriteTo(t *testing.T) {
}
defer os.RemoveAll(tmppath)

path := tmppath + "/output"
path := filepath.Join(tmppath, "output")

err = WriteTo(sf, path)
if err != nil {
t.Fatal(err)
}
expected := map[string]string{
".": "",
"1": "Some text!\n",
"2": "beep",
"3": "",
"4": "boop",
"5": "",
"5/a": "foobar",
".": "",
"1": "Some text!\n",
"2": "beep",
"3": "",
"4": "boop",
"5": "",
filepath.FromSlash("5/a"): "foobar",
}
err = filepath.Walk(path, func(cpath string, info os.FileInfo, err error) error {
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions files/serialfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
defer os.RemoveAll(tmppath)

testInputs := map[string]string{
"1": "Some text!\n",
"2": "beep",
"3": "",
"4": "boop",
"5": "",
"5/a": "foobar",
".6": "thing",
"7": "",
"7/.foo": "bla",
".8": "",
".8/foo": "bla",
"1": "Some text!\n",
"2": "beep",
"3": "",
"4": "boop",
"5": "",
filepath.FromSlash("5/a"): "foobar",
".6": "thing",
"7": "",
filepath.FromSlash("7/.foo"): "bla",
".8": "",
filepath.FromSlash(".8/foo"): "bla",
}
fileFilter, err := NewFilter("", []string{"9", "10"}, hidden)
if err != nil {
t.Fatal(err)
}
if withIgnoreRules {
testInputs["9"] = ""
testInputs["9/b"] = "bebop"
testInputs[filepath.FromSlash("9/b")] = "bebop"
testInputs["10"] = ""
testInputs["10/.c"] = "doowop"
testInputs[filepath.FromSlash("10/.c")] = "doowop"
}

for p, c := range testInputs {
Expand All @@ -76,7 +76,7 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {

testInputs:
for p := range testInputs {
components := strings.Split(p, "/")
components := strings.Split(p, string(filepath.Separator))
var stat os.FileInfo
for i := range components {
stat, err = os.Stat(filepath.Join(
Expand Down

0 comments on commit 302094f

Please sign in to comment.