-
Notifications
You must be signed in to change notification settings - Fork 6
/
poe_settings_test.go
138 lines (125 loc) · 3.89 KB
/
poe_settings_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
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"strings"
"testing"
"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
)
func TestFindPortConfigInHtml(t *testing.T) {
tests := []struct {
model string
fileName string
expectedSettingsLength int
expectedPortIndex string
expectedPort0Pwr bool
expectedPort1Pwr bool
expectedPwrMode string
expectedPortPrio string
expectedLimitType string
expectedPwrLimit string
expectedDetecType string
expectedPortName string
}{
{
model: "GS305EP",
fileName: "PoEPortConfig.cgi.html",
expectedSettingsLength: 4,
expectedPortIndex: "",
expectedPort0Pwr: false,
expectedPort1Pwr: true,
expectedPwrMode: "3",
expectedPortPrio: "0",
expectedLimitType: "2",
expectedPwrLimit: "30.0",
expectedDetecType: "2",
expectedPortName: "link to - sw128 ",
},
{
model: "GS308EPP",
fileName: "PoEPortConfig.cgi.html",
expectedSettingsLength: 8,
expectedPortIndex: "",
expectedPort0Pwr: false,
expectedPort1Pwr: false,
expectedPwrMode: "3",
expectedPortPrio: "0",
expectedLimitType: "2",
expectedPwrLimit: "30.0",
expectedDetecType: "2",
expectedPortName: "",
},
}
for _, test := range tests {
t.Run(test.model, func(t *testing.T) {
// from type inference, settings is of type []PoePortSetting
settings, err := findPoeSettingsInHtml(strings.NewReader(loadTestFile(test.model, test.fileName)))
then.AssertThat(t, err, is.Nil())
then.AssertThat(t, settings, has.Length[PoePortSetting](test.expectedSettingsLength))
setting := settings[0]
then.AssertThat(t, setting.PortIndex, is.EqualTo(int8(1)))
then.AssertThat(t, setting.PortPwr, is.EqualTo(test.expectedPort0Pwr))
then.AssertThat(t, setting.PwrMode, is.EqualTo(test.expectedPwrMode))
then.AssertThat(t, setting.PortPrio, is.EqualTo(test.expectedPortPrio))
then.AssertThat(t, setting.LimitType, is.EqualTo(test.expectedLimitType))
then.AssertThat(t, setting.PwrLimit, is.EqualTo(test.expectedPwrLimit))
then.AssertThat(t, setting.DetecType, is.EqualTo(test.expectedDetecType))
setting = settings[1]
then.AssertThat(t, setting.PortPwr, is.EqualTo(test.expectedPort1Pwr))
// Tests that the space is not removed if the user has deliberately added it
then.AssertThat(t, setting.PortName, is.EqualTo(test.expectedPortName))
})
}
}
func TestPrettyPrintSettings(t *testing.T) {
tests := []struct {
model string
fileName string
expectedVal int
}{
{
model: "GS305EP",
fileName: "PoEPortConfig.cgi.html",
expectedVal: 4,
},
{
model: "GS308EPP",
fileName: "PoEPortConfig.cgi.html",
expectedVal: 8,
},
}
for _, test := range tests {
t.Run(test.model, func(t *testing.T) {
settings, err := findPoeSettingsInHtml(strings.NewReader(loadTestFile(test.model, test.fileName)))
then.AssertThat(t, err, is.Nil())
then.AssertThat(t, settings, has.Length[PoePortSetting](test.expectedVal))
prettyPrintSettings(MarkdownFormat, settings)
})
}
}
func TestPrettyPrintJsonSettings(t *testing.T) {
tests := []struct {
model string
fileName string
expectedVal int
}{
{
model: "GS305EP",
fileName: "PoEPortConfig.cgi.html",
expectedVal: 4,
},
{
model: "GS308EPP",
fileName: "PoEPortConfig.cgi.html",
expectedVal: 8,
},
}
for _, test := range tests {
t.Run(test.model, func(t *testing.T) {
settings, err := findPoeSettingsInHtml(strings.NewReader(loadTestFile(test.model, test.fileName)))
then.AssertThat(t, err, is.Nil())
then.AssertThat(t, settings, has.Length[PoePortSetting](test.expectedVal))
prettyPrintSettings(JsonFormat, settings)
})
}
}