29 lines
958 B
Go
29 lines
958 B
Go
package frame
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMetaFrameEncode(t *testing.T) {
|
|
m := &MetaFrame{tid: randString()}
|
|
m.SetBroadcast(true)
|
|
tidBuf := []byte(m.tid)
|
|
result := []byte{0x80 | byte(TagOfMetaFrame), byte(1 + 1 + len(tidBuf) + 2 + 3), byte(TagOfTransactionId), byte(len(tidBuf))}
|
|
result = append(result, tidBuf...)
|
|
result = append(result, byte(TagOfSourceId), 0x0)
|
|
result = append(result, byte(TagOfBroadcast), 0x1, 0x1)
|
|
assert.Equal(t, result, m.Encode())
|
|
}
|
|
|
|
func TestMetaFrameDecode(t *testing.T) {
|
|
buf := []byte{0x80 | byte(TagOfMetaFrame), 0x0C, byte(TagOfTransactionId), 0x04, 0x31, 0x32, 0x33, 0x34, byte(TagOfSourceId), 0x01, 0x31, byte(TagOfBroadcast), 0x01, 0x01}
|
|
meta := &MetaFrame{}
|
|
err := DecodeToMetaFrame(buf, meta)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, "1234", meta.TransactionId())
|
|
assert.EqualValues(t, "1", meta.SourceId())
|
|
assert.EqualValues(t, true, meta.IsBroadcast())
|
|
}
|