diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-27 14:07:22 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-27 14:07:22 -0800 |
commit | 31f920a06aa5d7e7cf363645dac02f6e798fffb1 (patch) | |
tree | ddd60f794c193e1a407e78b5ca94d0a83466fd78 /formats/objfile/common_test.go | |
parent | e6855829c4df2861e779adcccbb422e7c0830afd (diff) | |
download | go-git-31f920a06aa5d7e7cf363645dac02f6e798fffb1.tar.gz |
Improved objfile error handling and test coverage
Diffstat (limited to 'formats/objfile/common_test.go')
-rw-r--r-- | formats/objfile/common_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/formats/objfile/common_test.go b/formats/objfile/common_test.go index 4727685..0c5a4cd 100644 --- a/formats/objfile/common_test.go +++ b/formats/objfile/common_test.go @@ -1,6 +1,7 @@ package objfile import ( + "bytes" "encoding/base64" "testing" @@ -67,3 +68,33 @@ var objfileFixtures = []objfileFixture{ } func Test(t *testing.T) { TestingT(t) } + +type SuiteCommon struct{} + +var _ = Suite(&SuiteCommon{}) + +func (s *SuiteCommon) TestHeaderReadEmpty(c *C) { + var h header + c.Assert(h.Read(new(bytes.Buffer)), Equals, ErrHeader) +} + +func (s *SuiteCommon) TestHeaderReadGarbage(c *C) { + var h header + c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, 3, 4, 5})), Equals, ErrHeader) + c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, 3, 4, 5, '0'})), Equals, ErrHeader) +} + +func (s *SuiteCommon) TestHeaderReadInvalidType(c *C) { + var h header + c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, ' ', 4, 5, 0})), Equals, core.ErrInvalidType) +} + +func (s *SuiteCommon) TestHeaderReadInvalidSize(c *C) { + var h header + c.Assert(h.Read(bytes.NewBuffer([]byte{'b', 'l', 'o', 'b', ' ', 'a', 0})), Equals, ErrHeader) +} + +func (s *SuiteCommon) TestHeaderReadNegativeSize(c *C) { + var h header + c.Assert(h.Read(bytes.NewBuffer([]byte{'b', 'l', 'o', 'b', ' ', '-', '1', 0})), Equals, ErrNegativeSize) +} |