-
Notifications
You must be signed in to change notification settings - Fork 23
/
usg_test.go
61 lines (54 loc) · 1.69 KB
/
usg_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
package unifi // nolint: testpackage
import (
_ "embed"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUSGUnmarshalJSON(t *testing.T) {
testcontroller511 := `{
"gw": {
"site_id": "mySite",
"o": "gw",
"oid": "00:00:00:00:00:00",
"gw": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:50:00Z",
"bytes": 0,
"duration": 3590568000,
"wan-rx_packets": 299729434558,
"wan-rx_bytes": 299882768958208,
"wan-tx_packets": 249639259523,
"wan-tx_bytes": 169183252492369,
"lan-rx_packets": 78912349453,
"lan-rx_bytes": 37599596992669,
"lan-tx_packets": 12991234992,
"lan-tx_bytes": 11794664098210}}`
testcontroller510 := `{
"site_id": "mySite",
"o": "gw",
"oid": "00:00:00:00:00:00",
"gw": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:50:00Z",
"bytes": 0,
"duration": 3590568000,
"wan-rx_packets": 299729434558,
"wan-rx_bytes": 299882768958208,
"wan-tx_packets": 249639259523,
"wan-tx_bytes": 169183252492369,
"lan-rx_packets": 78912349453,
"lan-rx_bytes": 37599596992669,
"lan-tx_packets": 12991234992,
"lan-tx_bytes": 11794664098210}`
t.Parallel()
a := assert.New(t)
u := &USGStat{}
lanRx := float64(37599596992669)
err := u.UnmarshalJSON([]byte(testcontroller510))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(lanRx, u.LanRxBytes.Val, "data was not properly unmarshaled")
u = &USGStat{} // reset
err = u.UnmarshalJSON([]byte(testcontroller511))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(lanRx, u.LanRxBytes.Val, "data was not properly unmarshaled")
}