-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
64 lines (56 loc) · 1.28 KB
/
auth_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
package mq
import (
"bytes"
"fmt"
"testing"
"github.com/eclipse/paho.golang/packets"
)
func ExampleAuth_String() {
p := NewAuth()
fmt.Println(p)
fmt.Print(DocumentFlags(p))
// output:
// AUTH ---- 2 bytes
// 3210 Size
//
// 3-0 reserved
}
func TestAuth(t *testing.T) {
p := NewAuth()
eq(t, p.SetReasonCode, p.ReasonCode, MalformedPacket)
eq(t, p.SetAuthMethod, p.AuthMethod, "digest")
eq(t, p.SetAuthData, p.AuthData, []byte("sha"))
eq(t, p.SetReasonString, p.ReasonString, "some reason")
p.AddUserProp("color", "red")
testControlPacket(t, p)
// String
if v := p.String(); v != "AUTH ---- 46 bytes" {
t.Error(v)
}
}
func BenchmarkAuth(b *testing.B) {
b.Run("our", func(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
p := NewAuth()
p.AddUserProp("color", "red")
p.SetReasonCode(ReAuthenticate)
p.WriteTo(&buf)
ReadPacket(&buf)
}
})
b.Run("their", func(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
p := packets.NewControlPacket(packets.AUTH)
c := p.Content.(*packets.Auth)
c.ReasonCode = packets.AuthReauthenticate
c.Properties = &packets.Properties{}
c.Properties.User = append(
c.Properties.User, packets.User{"color", "red"},
)
p.WriteTo(&buf)
packets.ReadPacket(&buf)
}
})
}