forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_test.go
87 lines (81 loc) · 1.77 KB
/
connection_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
package ipmi_sensor
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewConnection(t *testing.T) {
testData := []struct {
addr string
con *Connection
}{
{
"USERID:PASSW0RD@lan(192.168.1.1)",
&Connection{
Hostname: "192.168.1.1",
Username: "USERID",
Password: "PASSW0RD",
Interface: "lan",
Privilege: "USER",
HexKey: "0001",
},
},
{
"USERID:PASS:!@#$%^&*(234)_+W0RD@lan(192.168.1.1)",
&Connection{
Hostname: "192.168.1.1",
Username: "USERID",
Password: "PASS:!@#$%^&*(234)_+W0RD",
Interface: "lan",
Privilege: "USER",
HexKey: "0001",
},
},
// test connection doesn't panic if incorrect symbol used
{
"USERID@PASSW0RD@lan(192.168.1.1)",
&Connection{
Hostname: "192.168.1.1",
Username: "",
Password: "",
Interface: "lan",
Privilege: "USER",
HexKey: "0001",
},
},
}
for _, v := range testData {
require.EqualValues(t, v.con, NewConnection(v.addr, "USER", "0001"))
}
}
func TestGetCommandOptions(t *testing.T) {
testData := []struct {
connection *Connection
options []string
}{
{
&Connection{
Hostname: "192.168.1.1",
Username: "user",
Password: "password",
Interface: "lan",
Privilege: "USER",
HexKey: "0001",
},
[]string{"-H", "192.168.1.1", "-U", "user", "-P", "password", "-I", "lan", "-y", "0001", "-L", "USER"},
},
{
&Connection{
Hostname: "192.168.1.1",
Username: "user",
Password: "password",
Interface: "lan",
Privilege: "USER",
HexKey: "",
},
[]string{"-H", "192.168.1.1", "-U", "user", "-P", "password", "-I", "lan", "-L", "USER"},
},
}
for _, data := range testData {
require.EqualValues(t, data.options, data.connection.options())
}
}