-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisconnect_test.go
53 lines (45 loc) · 968 Bytes
/
disconnect_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
package mq
import (
"bytes"
"fmt"
"testing"
)
func ExampleDisconnect_String() {
p := NewDisconnect()
fmt.Println(p)
fmt.Print(DocumentFlags(p))
// output:
// DISCONNECT ---- 2 bytes
// 3210 Size
//
// 3-0 reserved
}
func ExampleDisconnect_stringWithReason() {
p := NewDisconnect()
p.SetReasonCode(QoSNotSupported)
fmt.Println(p)
fmt.Print(DocumentFlags(p))
// output:
// DISCONNECT ---- 4 bytes QoSNotSupported!
// 3210 Size
//
// 3-0 reserved
}
func TestDisconnect(t *testing.T) {
p := NewDisconnect()
// normal disconnect
testControlPacket(t, p)
eq(t, p.SetReasonCode, p.ReasonCode, MalformedPacket)
p.AddUserProp("color", "red")
testControlPacket(t, p)
}
func BenchmarkDisconnect_UnmarshalBinary(b *testing.B) {
p := NewDisconnect()
var buf bytes.Buffer
p.WriteTo(&buf)
data := buf.Bytes()[1:] // without the fixed header
var in Disconnect
for i := 0; i < b.N; i++ {
in.UnmarshalBinary(data[1:])
}
}