-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwifi_types_test.go
99 lines (90 loc) · 2.13 KB
/
wifi_types_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
package hitron
import (
"encoding/json"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
//nolint:govet
func TestWiFiModeString(t *testing.T) {
testdata := []struct {
in WiFiMode
expected string
}{
{WiFiModeB, "802.11b"},
{WiFiModeG, "802.11g"},
{WiFiModeN, "802.11n"},
{WiFiModeA, "802.11a"},
{WiFiModeAC, "802.11ac"},
{WiFiModeB | WiFiModeG | WiFiModeN, "802.11b/g/n"},
{WiFiModeG | WiFiModeN, "802.11g/n"},
{WiFiModeA | WiFiModeN | WiFiModeAC, "802.11a/n/ac"},
}
for _, d := range testdata {
t.Run(d.expected, func(t *testing.T) {
assert.Equal(t, d.expected, d.in.String())
})
}
}
func mustParseMac(in string) net.HardwareAddr {
mac, err := net.ParseMAC(in)
if err != nil {
panic(err)
}
return mac
}
func TestWiFiClientEntry_UnmarshalJSON(t *testing.T) {
testdata := []struct {
in []byte
expected WiFiClientEntry
}{
{
in: []byte(`{
"index": 1, "band": "2.4G", "ssid": "XXX",
"hostname": "with-int-aid", "mac":"AA:6F:99:8D:CB:A4",
"aid": 1, "rssi": "-70", "br": "51M",
"pm": "11NG_HT20", "ch": "11", "bw": "20MHz"
}`),
expected: WiFiClientEntry{
Index: 1,
Band: "2.4G",
SSID: "XXX",
Hostname: "with-int-aid",
MACAddr: mustParseMac("AA:6F:99:8D:CB:A4"),
AID: 1,
RSSI: -70,
DataRate: 51 * 1024 * 1024,
PhyMode: "11NG_HT20",
Channel: 11,
Bandwidth: 20_000_000,
},
},
{
in: []byte(`{
"index": 1, "band": "2.4G", "ssid": "XXX",
"hostname": "with-string-aid", "mac":"AA:6F:99:8D:CB:A4",
"aid": "42", "rssi": "-70", "br": "51M",
"pm": "11NG_HT20", "ch": "11", "bw": "20MHz"
}`),
expected: WiFiClientEntry{
Index: 1,
Band: "2.4G",
SSID: "XXX",
Hostname: "with-string-aid",
MACAddr: mustParseMac("AA:6F:99:8D:CB:A4"),
AID: 42,
RSSI: -70,
DataRate: 51 * 1024 * 1024,
PhyMode: "11NG_HT20",
Channel: 11,
Bandwidth: 20_000_000,
},
},
}
for _, d := range testdata {
entry := WiFiClientEntry{}
err := json.Unmarshal(d.in, &entry)
assert.NoError(t, err)
assert.Equal(t, d.expected, entry)
}
}