Skip to content

Commit 0aa8204

Browse files
tarutistrib
authored andcommitted
Add test for truncating files
1 parent 2db7bbc commit 0aa8204

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/basic.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,22 @@ func (s *BasicSuite) TestWriteFile(c *C) {
562562

563563
c.Assert(f.Close(), IsNil)
564564
}
565+
566+
func (s *BasicSuite) TestTruncate(c *C) {
567+
f, err := s.FS.Create("foo")
568+
c.Assert(err, IsNil)
569+
570+
for _, sz := range []int64{4, 7, 2, 30, 0, 1} {
571+
err = f.Truncate(sz)
572+
c.Assert(err, IsNil)
573+
574+
bs, err := ioutil.ReadAll(f)
575+
c.Assert(err, IsNil)
576+
c.Assert(len(bs), Equals, int(sz))
577+
578+
_, err = f.Seek(0, io.SeekStart)
579+
c.Assert(err, IsNil)
580+
}
581+
582+
c.Assert(f.Close(), IsNil)
583+
}

0 commit comments

Comments
 (0)