-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcm_types_test.go
126 lines (118 loc) · 2.45 KB
/
cm_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package hitron
import (
"encoding/json"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestParseDHCPLeaseTime(t *testing.T) {
testdata := []struct {
in string
dur time.Duration
}{
{"", 0},
{"S: 30", 30 * time.Second},
{"D: 0 H: 1 M: 2 S: 3", time.Hour + 2*time.Minute + 3*time.Second},
{"D: 0 H: 00 M: 00 S: 00", 0},
{"D: 6 H: 09 M: 25 S: 55", 6*24*time.Hour + 9*time.Hour + 25*time.Minute + 55*time.Second},
{"D: 6 weird {corrupt{ ][entry", 6 * 24 * time.Hour},
}
for _, d := range testdata {
t.Run(d.in, func(t *testing.T) {
out := parseDHCPLeaseDuration(d.in)
assert.Equal(t, d.dur, out)
})
}
}
func TestPortInfoUnmarshalJSON(t *testing.T) {
in := `{
"portId": "1",
"frequency": "615000000",
"modulation": "QAM256",
"signalStrength": "2.500",
"snr": "37.636",
"channelId": "11",
"dsoctets": "20883398",
"correcteds": "1",
"uncorrect": "0"
}`
expected := &PortInfo{
PortID: "1",
Frequency: 615000000,
Modulation: "QAM256",
SignalStrength: 2.5,
ChannelID: "11",
SNR: 37.636,
DsOctets: 20883398,
Correcteds: 1,
Uncorrect: 0,
}
out := &PortInfo{}
err := json.Unmarshal([]byte(in), out)
assert.NoError(t, err)
assert.Equal(t, expected, out)
in = `{
"portId": "8",
"frequency": "",
"modulation": "QAM256",
"signalStrength": false,
"snr": false,
"channelId": "0",
"dsoctets": "0",
"correcteds": "0",
"uncorrect": "0"
}`
out = &PortInfo{}
err = json.Unmarshal([]byte(in), out)
assert.Error(t, err)
}
func TestCMDsInfoUnmarshalJSON(t *testing.T) {
in := `{
"errCode": "000",
"errMsg": "",
"Freq_List": [
{
"portId": "1",
"frequency": "615000000",
"modulation": "QAM256",
"signalStrength": "2.500",
"snr": "37.636",
"channelId": "11",
"dsoctets": "20883398",
"correcteds": "1",
"uncorrect": "0"
},
{
"portId": "8",
"frequency": "",
"modulation": "QAM256",
"signalStrength": false,
"snr": false,
"channelId": "0",
"dsoctets": "0",
"correcteds": "0",
"uncorrect": "0"
}
]
}`
expected := &CMDsInfo{
Error: NoError,
Ports: []PortInfo{
{
PortID: "1",
Frequency: 615000000,
Modulation: "QAM256",
SignalStrength: 2.5,
ChannelID: "11",
SNR: 37.636,
DsOctets: 20883398,
Correcteds: 1,
Uncorrect: 0,
},
},
}
out := &CMDsInfo{}
err := json.Unmarshal([]byte(in), out)
assert.NoError(t, err)
assert.Equal(t, expected, out)
}