diff options
Diffstat (limited to 'utils/fs')
-rw-r--r-- | utils/fs/memory/memory.go | 2 | ||||
-rw-r--r-- | utils/fs/test/fs_suite.go | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/utils/fs/memory/memory.go b/utils/fs/memory/memory.go index ef54c37..398ac35 100644 --- a/utils/fs/memory/memory.go +++ b/utils/fs/memory/memory.go @@ -91,7 +91,7 @@ func (fs *Memory) ReadDir(base string) (entries []fs.FileInfo, err error) { parts := strings.Split(fullpath, string(separator)) if len(parts) == 1 { - entries = append(entries, newFileInfo(fs.base, fullpath, f.content.Len())) + entries = append(entries, &fileInfo{name: parts[0], size: f.content.Len()}) continue } diff --git a/utils/fs/test/fs_suite.go b/utils/fs/test/fs_suite.go index 5aa99e6..01d6112 100644 --- a/utils/fs/test/fs_suite.go +++ b/utils/fs/test/fs_suite.go @@ -256,6 +256,48 @@ func (s *FilesystemSuite) TestReadDirAndDir(c *C) { c.Assert(info, HasLen, 2) } +func (s *FilesystemSuite) TestReadDirFileInfo(c *C) { + f, err := s.Fs.Create("foo") + c.Assert(err, IsNil) + n, err := f.Write([]byte{'F', 'O', 'O'}) + c.Assert(n, Equals, 3) + c.Assert(err, IsNil) + c.Assert(f.Close(), IsNil) + + info, err := s.Fs.ReadDir("/") + c.Assert(err, IsNil) + c.Assert(info, HasLen, 1) + + c.Assert(info[0].Size(), Equals, int64(3)) + c.Assert(info[0].IsDir(), Equals, false) + c.Assert(info[0].Name(), Equals, "foo") +} + +func (s *FilesystemSuite) TestReadDirFileInfoDirs(c *C) { + files := []string{"qux/baz/foo"} + for _, name := range files { + f, err := s.Fs.Create(name) + c.Assert(err, IsNil) + n, err := f.Write([]byte{'F', 'O', 'O'}) + c.Assert(n, Equals, 3) + c.Assert(err, IsNil) + c.Assert(f.Close(), IsNil) + } + + info, err := s.Fs.ReadDir("qux") + c.Assert(err, IsNil) + c.Assert(info, HasLen, 1) + c.Assert(info[0].IsDir(), Equals, true) + c.Assert(info[0].Name(), Equals, "baz") + + info, err = s.Fs.ReadDir("qux/baz") + c.Assert(err, IsNil) + c.Assert(info, HasLen, 1) + c.Assert(info[0].Size(), Equals, int64(3)) + c.Assert(info[0].IsDir(), Equals, false) + c.Assert(info[0].Name(), Equals, "foo") +} + func (s *FilesystemSuite) TestDirStat(c *C) { files := []string{"foo", "bar", "qux/baz", "qux/qux"} for _, name := range files { |