forked from unpoller/unifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusw_test.go
75 lines (70 loc) · 1.78 KB
/
usw_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
package unifi // nolint: testpackage
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testGetControllerJSON() (string, string) {
return `{
"sw": {
"site_id": "mySite",
"o": "sw",
"oid": "00:00:00:00:00:00",
"sw": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:40:00Z",
"rx_packets": 321,
"rx_bytes": 321,
"rx_errors": 123,
"rx_dropped": 123,
"rx_crypts": 123,
"rx_frags": 123,
"tx_packets": 123,
"tx_bytes": 123,
"tx_errors": 0,
"tx_dropped": 0,
"tx_retries": 0,
"rx_multicast": 123,
"rx_broadcast": 123,
"tx_multicast": 123,
"tx_broadcast": 123,
"bytes": 123,
"duration": 123}}`,
`{
"site_id": "mySite",
"o": "sw",
"oid": "00:00:00:00:00:00",
"sw": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:40:00Z",
"rx_packets": 321,
"rx_bytes": 321,
"rx_errors": 123,
"rx_dropped": 123,
"rx_crypts": 123,
"rx_frags": 123,
"tx_packets": 123,
"tx_bytes": 123,
"tx_errors": 0,
"tx_dropped": 0,
"tx_retries": 0,
"rx_multicast": 123,
"rx_broadcast": 123,
"tx_multicast": 123,
"tx_broadcast": 123,
"bytes": 123,
"duration": 123}`
}
func TestUSWUnmarshalJSON(t *testing.T) {
t.Parallel()
a := assert.New(t)
testcontroller511, testcontroller510 := testGetControllerJSON()
rxMulticast := 123
u := &USWStat{}
err := u.UnmarshalJSON([]byte(testcontroller510))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(float64(rxMulticast), u.RxMulticast.Val, "data was not properly unmarshaled")
u = &USWStat{} // reset
err = u.UnmarshalJSON([]byte(testcontroller511))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(float64(rxMulticast), u.RxMulticast.Val, "data was not properly unmarshaled")
}