aboutsummaryrefslogtreecommitdiffstats
path: root/pktline/decoder_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros Ortiz <mcuadros@gmail.com>2015-04-05 23:34:43 +0200
committerMáximo Cuadros Ortiz <mcuadros@gmail.com>2015-04-06 04:12:04 +0200
commit5d7303c49ac984a9fec60523f2d5297682e16646 (patch)
tree53ac3a7eae7e271e58cc37ab1b7d2c27f3f2a9e5 /pktline/decoder_test.go
downloadgo-git-5d7303c49ac984a9fec60523f2d5297682e16646.tar.gz
some refactor in folders and crawler
Diffstat (limited to 'pktline/decoder_test.go')
-rw-r--r--pktline/decoder_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/pktline/decoder_test.go b/pktline/decoder_test.go
new file mode 100644
index 0000000..a0f85ce
--- /dev/null
+++ b/pktline/decoder_test.go
@@ -0,0 +1,70 @@
+package pktline
+
+import (
+ "strings"
+ "testing"
+
+ . "gopkg.in/check.v1"
+)
+
+func Test(t *testing.T) { TestingT(t) }
+
+type DecoderSuite struct{}
+
+var _ = Suite(&DecoderSuite{})
+
+func (s *DecoderSuite) TestReadLine(c *C) {
+ j := &Decoder{strings.NewReader("0006a\n")}
+
+ line, err := j.ReadLine()
+ c.Assert(err, IsNil)
+ c.Assert(line, Equals, "a\n")
+}
+
+func (s *DecoderSuite) TestReadLineBufferUnderflow(c *C) {
+ j := &Decoder{strings.NewReader("00e7a\n")}
+
+ line, err := j.ReadLine()
+ c.Assert(err, ErrorMatches, "unexepected string length")
+ c.Assert(line, Equals, "")
+}
+
+func (s *DecoderSuite) TestReadLineBufferInvalidLen(c *C) {
+ j := &Decoder{strings.NewReader("0001foo\n")}
+
+ line, err := j.ReadLine()
+ c.Assert(err, ErrorMatches, "invalid length")
+ c.Assert(line, Equals, "")
+}
+
+func (s *DecoderSuite) TestReadBlock(c *C) {
+ j := &Decoder{strings.NewReader("0006a\n")}
+
+ lines, err := j.ReadBlock()
+ c.Assert(err, IsNil)
+ c.Assert(lines, HasLen, 1)
+ c.Assert(lines[0], Equals, "a\n")
+}
+
+func (s *DecoderSuite) TestReadBlockWithFlush(c *C) {
+ j := &Decoder{strings.NewReader("0006a\n0006b\n00000006c\n")}
+
+ lines, err := j.ReadBlock()
+ c.Assert(err, IsNil)
+ c.Assert(lines, HasLen, 2)
+ c.Assert(lines[0], Equals, "a\n")
+ c.Assert(lines[1], Equals, "b\n")
+}
+
+func (s *DecoderSuite) TestReadAll(c *C) {
+ j := &Decoder{strings.NewReader("0006a\n0006b\n00000006c\n0006d\n0006e\n")}
+
+ lines, err := j.ReadAll()
+ c.Assert(err, IsNil)
+ c.Assert(lines, HasLen, 5)
+ c.Assert(lines[0], Equals, "a\n")
+ c.Assert(lines[1], Equals, "b\n")
+ c.Assert(lines[2], Equals, "c\n")
+ c.Assert(lines[3], Equals, "d\n")
+ c.Assert(lines[4], Equals, "e\n")
+}