diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-20 11:30:01 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-20 11:30:01 +0100 |
commit | 2e60c554dbe56eed3e9a503d03fed01b459d029a (patch) | |
tree | 47ef669288c73147f1d0992912f8228828d3d5b4 /utils/fs | |
parent | 16d86605732ba3198c0acd4317b53cf4991a7d4d (diff) | |
download | go-git-2e60c554dbe56eed3e9a503d03fed01b459d029a.tar.gz |
utils: fs, memory fix ReadDir, error getting filename
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 { |