-
Notifications
You must be signed in to change notification settings - Fork 2
/
event_test.go
63 lines (59 loc) · 1.47 KB
/
event_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
package wpaclient
import (
"errors"
"fmt"
"reflect"
"testing"
)
func TestParseEvent(t *testing.T) {
tests := []struct {
name string
buf []byte
ev *Event
}{
{
name: "short buf",
buf: []byte("MSG\n"),
ev: &Event{Err: errors.New("message too short: MSG")},
},
{
name: "event severity",
buf: []byte("<a>Message"),
ev: &Event{Err: errors.New("parse severity: strconv.Atoi: parsing \"a\": invalid syntax")},
},
{
name: "event connected",
buf: []byte(fmt.Sprintf("<2>%s\n", WpaEventConnected)),
ev: &Event{Sev: 2, Message: WpaEventConnected},
},
{
name: "event auth failed",
buf: []byte(fmt.Sprintf("<3>%sOTP-T:Challenge 1235663 needed for SSID foobar\n", WpaCtrlReq)),
ev: &Event{Err: errors.New("parse networkID: strconv.Atoi: parsing \"T\": invalid syntax")},
},
{
name: "event auth request",
buf: []byte(fmt.Sprintf("<3>%sPASSWORD-1:Password needed for SSID foobar\n", WpaCtrlReq)),
ev: &Event{
Sev: 3,
Message: WpaCtrlReq,
AuthReq: &AuthReq{
ID: 1,
Type: "PASSWORD",
Text: "Password needed for SSID foobar",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ev := parseEvent(tt.buf)
if tt.ev.Err != nil && tt.ev.Err.Error() != ev.Err.Error() {
t.Errorf("Error expected %v, got %v", tt.ev.Err, ev.Err)
}
if tt.ev.Err == nil && !reflect.DeepEqual(tt.ev, ev) {
t.Errorf("Event expected %#v, got %#v", tt.ev, ev)
}
})
}
}