Skip to content

Commit

Permalink
tests: Fix tests in windows
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
pjbgf committed Dec 16, 2022
1 parent 0a54206 commit 38b02ce
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions util/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WalkSuite struct{}
func TestWalk(t *testing.T) { TestingT(t) }

var _ = Suite(&WalkSuite{})
var targetSubfolder = filepath.FromSlash("path/to/some/subfolder")

func (s *WalkSuite) TestWalkCanSkipTopDirectory(c *C) {
filesystem := memfs.New()
Expand Down Expand Up @@ -52,13 +53,13 @@ func (s *WalkSuite) TestWalkOnExistingFolder(c *C) {
return nil
}), IsNil)
c.Assert(discoveredPaths, Contains, "path")
c.Assert(discoveredPaths, Contains, "path/to")
c.Assert(discoveredPaths, Contains, "path/to/some")
c.Assert(discoveredPaths, Contains, "path/to/some/file")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder/that")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder/that/contain")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder/that/contain/file")
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/file"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder/that"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder/that/contain"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder/that/contain/file"))
}

func (s *WalkSuite) TestWalkCanSkipFolder(c *C) {
Expand All @@ -68,19 +69,19 @@ func (s *WalkSuite) TestWalkCanSkipFolder(c *C) {
discoveredPaths := []string{}
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
discoveredPaths = append(discoveredPaths, path)
if path == "path/to/some/subfolder" {
if path == targetSubfolder {
return filepath.SkipDir
}
return nil
}), IsNil)
c.Assert(discoveredPaths, Contains, "path")
c.Assert(discoveredPaths, Contains, "path/to")
c.Assert(discoveredPaths, Contains, "path/to/some")
c.Assert(discoveredPaths, Contains, "path/to/some/file")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain/file")
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/file"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain/file"))
}

func (s *WalkSuite) TestWalkStopsOnError(c *C) {
Expand All @@ -90,27 +91,27 @@ func (s *WalkSuite) TestWalkStopsOnError(c *C) {
discoveredPaths := []string{}
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
discoveredPaths = append(discoveredPaths, path)
if path == "path/to/some/subfolder" {
if path == targetSubfolder {
return errors.New("uncaught error")
}
return nil
}), NotNil)
c.Assert(discoveredPaths, Contains, "path")
c.Assert(discoveredPaths, Contains, "path/to")
c.Assert(discoveredPaths, Contains, "path/to/some")
c.Assert(discoveredPaths, Contains, "path/to/some/file")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain/file")
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/file"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain/file"))
}

func (s *WalkSuite) TestWalkForwardsStatErrors(c *C) {
memFilesystem := memfs.New()
filesystem := &fnFs{
Filesystem: memFilesystem,
lstat: func(path string) (os.FileInfo, error) {
if path == "path/to/some/subfolder" {
if path == targetSubfolder {
return nil, errors.New("uncaught error")
}
return memFilesystem.Lstat(path)
Expand All @@ -122,19 +123,19 @@ func (s *WalkSuite) TestWalkForwardsStatErrors(c *C) {
discoveredPaths := []string{}
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
discoveredPaths = append(discoveredPaths, path)
if path == "path/to/some/subfolder" {
if path == targetSubfolder {
c.Assert(err, NotNil)
}
return err
}), NotNil)
c.Assert(discoveredPaths, Contains, "path")
c.Assert(discoveredPaths, Contains, "path/to")
c.Assert(discoveredPaths, Contains, "path/to/some")
c.Assert(discoveredPaths, Contains, "path/to/some/file")
c.Assert(discoveredPaths, Contains, "path/to/some/subfolder")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain")
c.Assert(discoveredPaths, NotContain, "path/to/some/subfolder/that/contain/file")
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/file"))
c.Assert(discoveredPaths, Contains, filepath.FromSlash("path/to/some/subfolder"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain"))
c.Assert(discoveredPaths, NotContain, filepath.FromSlash("path/to/some/subfolder/that/contain/file"))
}

func createFile(c *C, filesystem billy.Filesystem, path string) {
Expand Down

0 comments on commit 38b02ce

Please sign in to comment.