From ecef908d30cf03808073e0ff21701a7e1c02c5be Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Thu, 22 Jul 2021 10:27:38 +0100 Subject: [PATCH 1/2] Mock `FileInfo.Sys()` to return `nil` explicitly Otherwise, this function call panics on windows. This commit was moved from ipfs/go-ipfs-files@73547d879f88980f233b3f929dbcaadabe233249 --- files/filter_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/filter_test.go b/files/filter_test.go index d33b11429..ad2e48cd9 100644 --- a/files/filter_test.go +++ b/files/filter_test.go @@ -16,6 +16,10 @@ func (m *mockFileInfo) Name() string { return m.name } +func (m *mockFileInfo) Sys() interface{} { + return nil +} + var _ os.FileInfo = &mockFileInfo{} func TestFileFilter(t *testing.T) { From 302094f964002d8d8058d566a67bf26175730c9a Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Thu, 22 Jul 2021 10:57:54 +0100 Subject: [PATCH 2/2] Normalize path separator in tests based in OS Use OS specific path separators in tests This commit was moved from ipfs/go-ipfs-files@ac10fa80a51edc0f32e9aa0a72de9fed5292a1ce --- files/filewriter_test.go | 16 ++++++++-------- files/serialfile_test.go | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/files/filewriter_test.go b/files/filewriter_test.go index 5809aba57..4d2150359 100644 --- a/files/filewriter_test.go +++ b/files/filewriter_test.go @@ -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 { diff --git a/files/serialfile_test.go b/files/serialfile_test.go index ee8da3ad3..ae7639691 100644 --- a/files/serialfile_test.go +++ b/files/serialfile_test.go @@ -29,17 +29,17 @@ 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 { @@ -47,9 +47,9 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) { } 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 { @@ -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(