aboutsummaryrefslogtreecommitdiffstats
path: root/pktline/encoder_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pktline/encoder_test.go')
-rw-r--r--pktline/encoder_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pktline/encoder_test.go b/pktline/encoder_test.go
new file mode 100644
index 0000000..091ad1c
--- /dev/null
+++ b/pktline/encoder_test.go
@@ -0,0 +1,34 @@
+package pktline
+
+import (
+ "io/ioutil"
+
+ . "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) 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()
+ e.AddLine("a")
+ e.AddFlush()
+ e.AddLine("b")
+
+ r := e.GetReader()
+ a, _ := ioutil.ReadAll(r)
+ c.Assert(string(a), Equals, "0006a\n00000006b\n")
+}