From 3aa0efc16a128fcd4fe8b7c12eb257f89f02b7f7 Mon Sep 17 00:00:00 2001 From: saxon Date: Mon, 28 Jan 2019 18:07:34 +1030 Subject: [PATCH] stream/mts/meta_test.go: added TestEncode to test Meta.Encoding function --- stream/mts/meta_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stream/mts/meta_test.go b/stream/mts/meta_test.go index 07f0e5e2..010c9b82 100644 --- a/stream/mts/meta_test.go +++ b/stream/mts/meta_test.go @@ -28,6 +28,7 @@ LICENSE package mts import ( + "bytes" "errors" "reflect" "testing" @@ -127,4 +128,23 @@ func TestDeleteAbsentKey(t *testing.T) { func TestEncode(t *testing.T) { meta := NewMeta() + meta.Add(tstKey1, tstData1) + meta.Add(tstKey2, tstData2) + + dataLen := len(tstKey1+tstData1+tstKey2+tstData2) + 3 + expectedOut := []byte{ + 0x00, + 0x10, + byte(dataLen >> 8), + byte(dataLen), + } + expectedOut = append(expectedOut, []byte( + tstKey1+"="+tstData1+"\t"+ + tstKey2+"="+tstData2)...) + + got := meta.Encode() + + if !bytes.Equal(expectedOut, got) { + t.Errorf("Did not get expected out. \nGot : %v \nwant: %v", got, expectedOut) + } }