From f6ed7424cbf33c7013332d7e95b4262a4bc4a523 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 7 Nov 2016 10:52:45 +0100 Subject: utils/fs: added test for open-read-seek. (#117) Previously we tested only seek on created files, not opened. --- utils/fs/test/fs_suite.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/utils/fs/test/fs_suite.go b/utils/fs/test/fs_suite.go index 74301f5..8c413bf 100644 --- a/utils/fs/test/fs_suite.go +++ b/utils/fs/test/fs_suite.go @@ -185,7 +185,7 @@ func (s *FilesystemSuite) testReadClose(c *C, f File, content string) { c.Assert(f.Close(), IsNil) } -func (s *FilesystemSuite) TestFileReadSeek(c *C) { +func (s *FilesystemSuite) TestFileCreateReadSeek(c *C) { f, err := s.Fs.Create("foo") c.Assert(err, IsNil) @@ -203,6 +203,29 @@ func (s *FilesystemSuite) TestFileReadSeek(c *C) { c.Assert(f.Close(), IsNil) } +func (s *FilesystemSuite) TestFileOpenReadSeek(c *C) { + f, err := s.Fs.Create("foo") + c.Assert(err, IsNil) + + n, err := f.Write([]byte("0123456789abcdefghijklmnopqrstuvwxyz")) + c.Assert(err, IsNil) + c.Assert(n, Equals, 36) + + c.Assert(f.Close(), IsNil) + + f, err = s.Fs.Open("foo") + c.Assert(err, IsNil) + + p, err := f.Seek(10, io.SeekStart) + c.Assert(err, IsNil) + c.Assert(int(p), Equals, 10) + + all, err := ioutil.ReadAll(f) + c.Assert(err, IsNil) + c.Assert(string(all), Equals, "abcdefghijklmnopqrstuvwxyz") + c.Assert(f.Close(), IsNil) +} + func (s *FilesystemSuite) TestFileCloseTwice(c *C) { f, err := s.Fs.Create("foo") c.Assert(err, IsNil) -- cgit