-
Notifications
You must be signed in to change notification settings - Fork 7
/
send_test.go
executable file
·44 lines (38 loc) · 1.12 KB
/
send_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package wkproto
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSendEncodeAndDecode(t *testing.T) {
var setting Setting
setting.Set(SettingNoEncrypt)
packet := &SendPacket{
Framer: Framer{
RedDot: true,
},
Expire: 100,
Setting: setting,
ClientSeq: 2,
ChannelID: "34341",
ChannelType: 2,
Payload: []byte("dsdsdsd1"),
}
packet.RedDot = true
codec := New()
// 编码
packetBytes, err := codec.EncodeFrame(packet, LatestVersion)
assert.NoError(t, err)
// 解码
resultPacket, _, err := codec.DecodeFrame(packetBytes, LatestVersion)
assert.NoError(t, err)
resultSendPacket, ok := resultPacket.(*SendPacket)
assert.Equal(t, true, ok)
// 比较
assert.Equal(t, packet.ClientSeq, resultSendPacket.ClientSeq)
assert.Equal(t, packet.ChannelID, resultSendPacket.ChannelID)
assert.Equal(t, packet.ChannelType, resultSendPacket.ChannelType)
assert.Equal(t, packet.Expire, resultSendPacket.Expire)
assert.Equal(t, packet.RedDot, resultSendPacket.RedDot)
assert.Equal(t, packet.Payload, resultSendPacket.Payload)
assert.Equal(t, packet.Setting, resultSendPacket.Setting)
}