-
Notifications
You must be signed in to change notification settings - Fork 103
/
messagetcp_test.go
36 lines (30 loc) · 794 Bytes
/
messagetcp_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
package coap
import (
"bytes"
"encoding/binary"
"testing"
)
func TestTCPDecodeMessageSmallWithPayload(t *testing.T) {
input := []byte{0, 0,
0x40, 0x1, 0x30, 0x39, 0x21, 0x3,
0x26, 0x77, 0x65, 0x65, 0x74, 0x61, 0x67,
0xff, 'h', 'i',
}
binary.BigEndian.PutUint16(input, uint16(len(input)-2))
msg, err := Decode(bytes.NewReader(input))
if err != nil {
t.Fatalf("Error parsing message: %v", err)
}
if msg.Type != Confirmable {
t.Errorf("Expected message type confirmable, got %v", msg.Type)
}
if msg.Code != GET {
t.Errorf("Expected message code GET, got %v", msg.Code)
}
if msg.MessageID != 12345 {
t.Errorf("Expected message ID 12345, got %v", msg.MessageID)
}
if !bytes.Equal(msg.Payload, []byte("hi")) {
t.Errorf("Incorrect payload: %q", msg.Payload)
}
}