aboutsummaryrefslogtreecommitdiffstats
path: root/formats/objfile/writer_test.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
commit31f920a06aa5d7e7cf363645dac02f6e798fffb1 (patch)
treeddd60f794c193e1a407e78b5ca94d0a83466fd78 /formats/objfile/writer_test.go
parente6855829c4df2861e779adcccbb422e7c0830afd (diff)
downloadgo-git-31f920a06aa5d7e7cf363645dac02f6e798fffb1.tar.gz
Improved objfile error handling and test coverage
Diffstat (limited to 'formats/objfile/writer_test.go')
-rw-r--r--formats/objfile/writer_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/formats/objfile/writer_test.go b/formats/objfile/writer_test.go
index 03b8370..0061f3f 100644
--- a/formats/objfile/writer_test.go
+++ b/formats/objfile/writer_test.go
@@ -38,9 +38,12 @@ func testWriter(c *C, dest io.Writer, hash core.Hash, typ core.ObjectType, conte
written, err := io.Copy(w, bytes.NewReader(content))
c.Assert(err, IsNil)
c.Assert(written, Equals, length)
+ c.Assert(w.Size(), Equals, int64(len(content)))
c.Assert(w.Hash(), Equals, hash) // Test Hash() before close
c.Assert(w.Close(), IsNil)
c.Assert(w.Hash(), Equals, hash) // Test Hash() after close
+ _, err = w.Write([]byte{1})
+ c.Assert(err, Equals, ErrClosed)
}
func (s *SuiteWriter) TestWriteOverflow(c *C) {
@@ -51,3 +54,16 @@ func (s *SuiteWriter) TestWriteOverflow(c *C) {
_, err = w.Write([]byte("56789"))
c.Assert(err, Equals, ErrOverflow)
}
+
+func (s *SuiteWriter) TestNewWriterInvalidType(c *C) {
+ var t core.ObjectType
+ _, err := NewWriter(new(bytes.Buffer), t, 8)
+ c.Assert(err, Equals, core.ErrInvalidType)
+}
+
+func (s *SuiteWriter) TestNewWriterInvalidSize(c *C) {
+ _, err := NewWriter(new(bytes.Buffer), core.BlobObject, -1)
+ c.Assert(err, Equals, ErrNegativeSize)
+ _, err = NewWriter(new(bytes.Buffer), core.BlobObject, -1651860)
+ c.Assert(err, Equals, ErrNegativeSize)
+}