-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathuap_test.go
63 lines (55 loc) · 1.7 KB
/
uap_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 unifi // nolint: testpackage
import (
_ "embed"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
//go:embed examples/uap.json
var uapSample []byte
func TestUAPUnmarshalJSON(t *testing.T) {
testcontroller511 := `{
"ap": {
"site_id": "mySite",
"o": "ap",
"oid": "00:00:00:00:00:00",
"ap": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:50:00Z",
"user-wifi1-rx_packets": 6596670,
"user-wifi0-rx_packets": 42659527,
"user-rx_packets": 49294197,
"guest-rx_packets": 0,
"wifi0-rx_packets": 42639527,
"wifi1-rx_packets": 6591670,
"rx_packets": 49299197}}`
testcontroller510 := `{
"site_id": "mySite",
"o": "ap",
"oid": "00:00:00:00:00:00",
"ap": "00:00:00:00:00:00",
"time": 1577742600000,
"datetime": "2019-12-30T09:50:00Z",
"user-wifi1-rx_packets": 6596670,
"user-wifi0-rx_packets": 42659527,
"user-rx_packets": 49294197,
"guest-rx_packets": 0,
"wifi0-rx_packets": 42639527,
"wifi1-rx_packets": 6591670,
"rx_packets": 49299197}`
t.Parallel()
a := assert.New(t)
rxPakcets := 49299197
u := &UAPStat{}
err := u.UnmarshalJSON([]byte(testcontroller510))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(float64(rxPakcets), u.RxPackets.Val, "data was not properly unmarshaled")
u = &UAPStat{} // reset
err = u.UnmarshalJSON([]byte(testcontroller511))
a.Nil(err, "must be no error unmarshaling test strings")
a.Equal(float64(rxPakcets), u.RxPackets.Val, "data was not properly unmarshaled")
uap := &UAP{}
err = json.Unmarshal(uapSample, uap)
a.Nil(err, "must be no error unmarshaling uap sample")
a.Equal(true, uap.Adopted.Val, "data was not properaly unmarshaled")
}