From 2e60c554dbe56eed3e9a503d03fed01b459d029a Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 20 Nov 2016 11:30:01 +0100 Subject: utils: fs, memory fix ReadDir, error getting filename --- utils/fs/test/fs_suite.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'utils/fs/test/fs_suite.go') 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 { -- cgit