stream/mts/meta_test.go: added TestEncode to test Meta.Encoding function

This commit is contained in:
saxon 2019-01-28 18:07:34 +10:30
parent 960c110acb
commit 3aa0efc16a
1 changed files with 20 additions and 0 deletions

View File

@ -28,6 +28,7 @@ LICENSE
package mts package mts
import ( import (
"bytes"
"errors" "errors"
"reflect" "reflect"
"testing" "testing"
@ -127,4 +128,23 @@ func TestDeleteAbsentKey(t *testing.T) {
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
meta := NewMeta() 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)
}
} }