network/frame/meta_frame_test.go

26 lines
776 B
Go

package frame
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMetaFrameEncode(t *testing.T) {
m := NewMetaFrame()
tidbuf := []byte(m.tid)
result := []byte{0x80 | byte(TagOfMetaFrame), byte(1 + 1 + len(tidbuf) + 2), byte(TagOfTransactionId), byte(len(tidbuf))}
result = append(result, tidbuf...)
result = append(result, byte(TagOfSourceId), 0x0)
assert.Equal(t, result, m.Encode())
}
func TestMetaFrameDecode(t *testing.T) {
buf := []byte{0x80 | byte(TagOfMetaFrame), 0x09, byte(TagOfTransactionId), 0x04, 0x31, 0x32, 0x33, 0x34, byte(TagOfSourceId), 0x01, 0x31}
meta, err := DecodeToMetaFrame(buf)
assert.NoError(t, err)
assert.EqualValues(t, "1234", meta.TransactionId())
assert.EqualValues(t, "1", meta.SourceId())
t.Logf("%# x", buf)
}