Skip to content

Commit 213e20d

Browse files
committed
utils: Walk, use os.FileInfo
fs.FileInfo has been introduced in go 1.16.5: golang/go@d4da735#diff-46ea5b4a04796237678b36cd31d68f74209c90d604123f15dcc4bcb605dbc136 go-billy supports the 2 latest versions The latest version of go is currently 1.16, hence use the previous instance in os instead
1 parent e0768be commit 213e20d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

util/walk_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package util_test
33
import (
44
"errors"
55
"fmt"
6-
"io/fs"
6+
"os"
77
"path/filepath"
88
"reflect"
99
"testing"
@@ -23,19 +23,19 @@ var _ = Suite(&WalkSuite{})
2323

2424
func (s *WalkSuite) TestWalkCanSkipTopDirectory(c *C) {
2525
filesystem := memfs.New()
26-
c.Assert(util.Walk(filesystem, "/root/that/does/not/exist", func(path string, info fs.FileInfo, err error) error { return filepath.SkipDir }), IsNil)
26+
c.Assert(util.Walk(filesystem, "/root/that/does/not/exist", func(path string, info os.FileInfo, err error) error { return filepath.SkipDir }), IsNil)
2727
}
2828

2929
func (s *WalkSuite) TestWalkReturnsAnErrorWhenRootDoesNotExist(c *C) {
3030
filesystem := memfs.New()
31-
c.Assert(util.Walk(filesystem, "/root/that/does/not/exist", func(path string, info fs.FileInfo, err error) error { return err }), NotNil)
31+
c.Assert(util.Walk(filesystem, "/root/that/does/not/exist", func(path string, info os.FileInfo, err error) error { return err }), NotNil)
3232
}
3333

3434
func (s *WalkSuite) TestWalkOnPlainFile(c *C) {
3535
filesystem := memfs.New()
3636
createFile(c, filesystem, "./README.md")
3737
discoveredPaths := []string{}
38-
c.Assert(util.Walk(filesystem, "./README.md", func(path string, info fs.FileInfo, err error) error {
38+
c.Assert(util.Walk(filesystem, "./README.md", func(path string, info os.FileInfo, err error) error {
3939
discoveredPaths = append(discoveredPaths, path)
4040
return nil
4141
}), IsNil)
@@ -47,7 +47,7 @@ func (s *WalkSuite) TestWalkOnExistingFolder(c *C) {
4747
createFile(c, filesystem, "path/to/some/subfolder/that/contain/file")
4848
createFile(c, filesystem, "path/to/some/file")
4949
discoveredPaths := []string{}
50-
c.Assert(util.Walk(filesystem, "path", func(path string, info fs.FileInfo, err error) error {
50+
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
5151
discoveredPaths = append(discoveredPaths, path)
5252
return nil
5353
}), IsNil)
@@ -66,7 +66,7 @@ func (s *WalkSuite) TestWalkCanSkipFolder(c *C) {
6666
createFile(c, filesystem, "path/to/some/subfolder/that/contain/file")
6767
createFile(c, filesystem, "path/to/some/file")
6868
discoveredPaths := []string{}
69-
c.Assert(util.Walk(filesystem, "path", func(path string, info fs.FileInfo, err error) error {
69+
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
7070
discoveredPaths = append(discoveredPaths, path)
7171
if path == "path/to/some/subfolder" {
7272
return filepath.SkipDir
@@ -88,7 +88,7 @@ func (s *WalkSuite) TestWalkStopsOnError(c *C) {
8888
createFile(c, filesystem, "path/to/some/subfolder/that/contain/file")
8989
createFile(c, filesystem, "path/to/some/file")
9090
discoveredPaths := []string{}
91-
c.Assert(util.Walk(filesystem, "path", func(path string, info fs.FileInfo, err error) error {
91+
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
9292
discoveredPaths = append(discoveredPaths, path)
9393
if path == "path/to/some/subfolder" {
9494
return errors.New("uncaught error")
@@ -109,7 +109,7 @@ func (s *WalkSuite) TestWalkForwardsStatErrors(c *C) {
109109
memFilesystem := memfs.New()
110110
filesystem := &fnFs{
111111
Filesystem: memFilesystem,
112-
lstat: func(path string) (fs.FileInfo, error) {
112+
lstat: func(path string) (os.FileInfo, error) {
113113
if path == "path/to/some/subfolder" {
114114
return nil, errors.New("uncaught error")
115115
}
@@ -120,7 +120,7 @@ func (s *WalkSuite) TestWalkForwardsStatErrors(c *C) {
120120
createFile(c, filesystem, "path/to/some/subfolder/that/contain/file")
121121
createFile(c, filesystem, "path/to/some/file")
122122
discoveredPaths := []string{}
123-
c.Assert(util.Walk(filesystem, "path", func(path string, info fs.FileInfo, err error) error {
123+
c.Assert(util.Walk(filesystem, "path", func(path string, info os.FileInfo, err error) error {
124124
discoveredPaths = append(discoveredPaths, path)
125125
if path == "path/to/some/subfolder" {
126126
c.Assert(err, NotNil)
@@ -147,10 +147,10 @@ func createFile(c *C, filesystem billy.Filesystem, path string) {
147147

148148
type fnFs struct {
149149
billy.Filesystem
150-
lstat func(path string) (fs.FileInfo, error)
150+
lstat func(path string) (os.FileInfo, error)
151151
}
152152

153-
func (f *fnFs) Lstat(path string) (fs.FileInfo, error) {
153+
func (f *fnFs) Lstat(path string) (os.FileInfo, error) {
154154
if f.lstat != nil {
155155
return f.lstat(path)
156156
}

0 commit comments

Comments
 (0)