-
Notifications
You must be signed in to change notification settings - Fork 24
/
usw_test.go
85 lines (78 loc) · 2.02 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
76
77
78
79
80
81
82
83
84
85
package unifi // nolint: testpackage
import (
_ "embed"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
//go:embed examples/usw.json
var uswSample []byte
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 := float64(123)
u := &USWStat{}
err := u.UnmarshalJSON([]byte(testcontroller510))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(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(rxMulticast, u.RxMulticast.Val, "data was not properly unmarshaled")
usw := &USW{}
err = json.Unmarshal(uswSample, usw)
a.Nil(err, "must be no error unmarshaling sample")
a.Equal(true, usw.Adopted.Val, "data was not properly unmarshaled")
}