-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
126 lines (110 loc) · 3.27 KB
/
message_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package nmeaais
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func buildPackets(raws []string) []*Packet {
var packets []*Packet
for _, raw := range raws {
packet, err := Parse(raw)
if err != nil {
fmt.Println(err)
}
packets = append(packets, packet)
}
return packets
}
func TestNmeaMessageProcessing(t *testing.T) {
Convey("When processing a multi-part message", t, func() {
Convey("That does not contain a matching number of packets", func() {
raws := []string{
"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return nil for the message", func() {
So(message, ShouldBeNil)
})
Convey("The processor should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("That has packets out of sequence", func() {
raws := []string{
"!AIVDM,2,2,3,B,1@0000000000000,2*55",
"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return nil for the message", func() {
So(message, ShouldBeNil)
})
Convey("The processor should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("That has packets from multiple messages ", func() {
raws := []string{
"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
"!AIVDM,2,2,,B,1@0000000000000,2*66",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return nil for the message", func() {
So(message, ShouldBeNil)
})
Convey("The processor should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("That is a valid NMEA 0183 format", func() {
raws := []string{
"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
"!AIVDM,2,2,3,B,1@0000000000000,2*55",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return a message", func() {
Convey("Where the message is not nil", func() {
So(message, ShouldNotBeNil)
})
})
Convey("The processor should not return an error", func() {
So(err, ShouldBeNil)
})
})
})
Convey("When processing a single-part message", t, func() {
Convey("That is a valid NMEA 0183 format", func() {
raws := []string{
"!AIVDM,1,1,,A,133m@ogP00PD;88MD5MTDww@2D7k,0*46",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return a message", func() {
Convey("Where the message is not nil", func() {
So(message, ShouldNotBeNil)
})
})
Convey("The processor should not return an error", func() {
So(err, ShouldBeNil)
})
})
})
Convey("When processing a message", t, func() {
Convey("That has an empty payload", func() {
raws := []string{
"!AIVDM,1,1,,A,,0*26",
}
packets := buildPackets(raws)
message, err := Process(packets)
Convey("The processor should return nil for the message", func() {
So(message, ShouldBeNil)
})
Convey("The processor should return an error", func() {
So(err, ShouldNotBeNil)
})
})
})
}