Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit f6ed742

Browse files
smolamcuadros
authored andcommitted
utils/fs: added test for open-read-seek. (#117)
Previously we tested only seek on created files, not opened.
1 parent 1b2f95c commit f6ed742

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

utils/fs/test/fs_suite.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (s *FilesystemSuite) testReadClose(c *C, f File, content string) {
185185
c.Assert(f.Close(), IsNil)
186186
}
187187

188-
func (s *FilesystemSuite) TestFileReadSeek(c *C) {
188+
func (s *FilesystemSuite) TestFileCreateReadSeek(c *C) {
189189
f, err := s.Fs.Create("foo")
190190
c.Assert(err, IsNil)
191191

@@ -203,6 +203,29 @@ func (s *FilesystemSuite) TestFileReadSeek(c *C) {
203203
c.Assert(f.Close(), IsNil)
204204
}
205205

206+
func (s *FilesystemSuite) TestFileOpenReadSeek(c *C) {
207+
f, err := s.Fs.Create("foo")
208+
c.Assert(err, IsNil)
209+
210+
n, err := f.Write([]byte("0123456789abcdefghijklmnopqrstuvwxyz"))
211+
c.Assert(err, IsNil)
212+
c.Assert(n, Equals, 36)
213+
214+
c.Assert(f.Close(), IsNil)
215+
216+
f, err = s.Fs.Open("foo")
217+
c.Assert(err, IsNil)
218+
219+
p, err := f.Seek(10, io.SeekStart)
220+
c.Assert(err, IsNil)
221+
c.Assert(int(p), Equals, 10)
222+
223+
all, err := ioutil.ReadAll(f)
224+
c.Assert(err, IsNil)
225+
c.Assert(string(all), Equals, "abcdefghijklmnopqrstuvwxyz")
226+
c.Assert(f.Close(), IsNil)
227+
}
228+
206229
func (s *FilesystemSuite) TestFileCloseTwice(c *C) {
207230
f, err := s.Fs.Create("foo")
208231
c.Assert(err, IsNil)

0 commit comments

Comments
 (0)