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 <pjbgf@linux.com>
  • Loading branch information
pjbgf committed Dec 16, 2022
1 parent 0a54206 commit f139c3c
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions util/walk_test.go
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 Down Expand Up @@ -110,7 +111,7 @@ func (s *WalkSuite) TestWalkForwardsStatErrors(c *C) {
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 f139c3c

Please sign in to comment.