-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket_test.go
More file actions
34 lines (29 loc) · 868 Bytes
/
packet_test.go
File metadata and controls
34 lines (29 loc) · 868 Bytes
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
package ais
import "testing"
import "github.com/stretchr/testify/assert"
var packet1 = "!AIVDM,1,1,,B,13@nocPP0427vl<`JO2``gwj08RD,0*11"
var packet1noChecksum = "!AIVDM,1,1,,B,13@nocPP0427vl<`JO2``gwj08RD,0"
var packet1wrongChecksum = "!AIVDM,1,1,,B,13@nocPP0427vl<`JO2``gwj08RD,0*12"
func TestParsePacket(t *testing.T) {
correctPacket, err := ParsePacket(packet1)
expected := &Packet{
Talker:"AI",
PacketType:"VDM",
Channel:"B",
FragCount:1,
FragNo:1,
SeqId:"",
FillBits:0,
Payload: "13@nocPP0427vl<`JO2``gwj08RD",
}
assert.Nil(t, err)
assert.EqualValues(t, expected, correctPacket)
}
func TestWrongChecksum(t *testing.T) {
_, err := ParsePacket(packet1wrongChecksum)
assert.Equal(t, ErrIncorrectChecksum, err)
}
func TestMissingChecksum(t *testing.T) {
_, err := ParsePacket(packet1noChecksum)
assert.Equal(t, ErrMissingChecksum, err)
}