diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 12:05:02 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 12:05:02 +0200 |
commit | 214e1dca024fb6da5ed65564d2de734df5dc2127 (patch) | |
tree | 0c2805a0676006690a8053ae8ccee388ccfc83fe /formats/pktline/encoder_test.go | |
parent | 70923099e61fa33f0bc5256d2f938fa44c4df10e (diff) | |
download | go-git-214e1dca024fb6da5ed65564d2de734df5dc2127.tar.gz |
format/pktline: review and improving coverage
Diffstat (limited to 'formats/pktline/encoder_test.go')
-rw-r--r-- | formats/pktline/encoder_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/formats/pktline/encoder_test.go b/formats/pktline/encoder_test.go new file mode 100644 index 0000000..f718c33 --- /dev/null +++ b/formats/pktline/encoder_test.go @@ -0,0 +1,50 @@ +package pktline + +import ( + "bytes" + "io/ioutil" + "strings" + + . "gopkg.in/check.v1" +) + +type EncoderSuite struct{} + +var _ = Suite(&EncoderSuite{}) + +func (s *EncoderSuite) TestEncode(c *C) { + line, err := Encode([]byte("a\n")) + c.Assert(err, IsNil) + c.Assert(string(line), Equals, "0006a\n") +} + +func (s *EncoderSuite) TestEncodeNil(c *C) { + line, err := Encode(nil) + c.Assert(err, IsNil) + c.Assert(string(line), Equals, "0000") +} + +func (s *EncoderSuite) TestEncodeOverflow(c *C) { + _, err := Encode(bytes.Repeat([]byte{'0'}, MaxLength+1)) + c.Assert(err, Equals, ErrOverflow) +} + +func (s *EncoderSuite) TestEncodeFromString(c *C) { + line, err := EncodeFromString("a\n") + c.Assert(err, IsNil) + c.Assert(string(line), Equals, "0006a\n") +} + +func (s *EncoderSuite) TestEncoder(c *C) { + e := NewEncoder() + c.Assert(e.AddLine("a"), IsNil) + e.AddFlush() + c.Assert(e.AddLine("b"), IsNil) + + over := strings.Repeat("0", MaxLength+1) + c.Assert(e.AddLine(over), Equals, ErrOverflow) + + r := e.Reader() + a, _ := ioutil.ReadAll(r) + c.Assert(string(a), Equals, "0006a\n00000006b\n") +} |