forked from kirinrastogi/proxysql-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil_test.go
More file actions
149 lines (134 loc) · 4.6 KB
/
Copy pathutil_test.go
File metadata and controls
149 lines (134 loc) · 4.6 KB
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
139
140
141
142
143
144
145
146
147
148
149
package proxysql
import (
"testing"
)
type hostQueryTests []struct {
in *hostQuery
out error
}
func TestValidateTableOpts(t *testing.T) {
tableTests := hostQueryTests{
{defaultHostQuery(), nil},
{defaultHostQuery().Table("runtime_mysql_servers"), nil},
{defaultHostQuery().Table("bad table"), ErrConfigBadTable},
}
for _, testCase := range tableTests {
obj := testCase.in
err := testCase.out
if validateTableOpts(obj) != err {
t.Logf("did not match expected validation. table %s, err %v", obj.table, err)
t.Fail()
}
}
}
func TestValidateHostgroupID(t *testing.T) {
hostgroupTests := hostQueryTests{
{defaultHostQuery(), nil},
{defaultHostQuery().HostgroupID(1), nil},
{defaultHostQuery().HostgroupID(-1), ErrConfigBadHostgroupID},
{defaultHostQuery().HostgroupID(2147483649), ErrConfigBadHostgroupID},
}
for _, testCase := range hostgroupTests {
obj := testCase.in
err := testCase.out
if validateHostgroupID(obj) != err {
t.Logf("did not match expected validation. hg %d, err %v", obj.host.hostgroup_id, err)
t.Fail()
}
}
}
func TestValidatePort(t *testing.T) {
portTests := hostQueryTests{
{defaultHostQuery(), nil},
{defaultHostQuery().Port(0), nil},
{defaultHostQuery().Port(65535), nil},
{defaultHostQuery().Port(-1), ErrConfigBadPort},
{defaultHostQuery().Port(65536), ErrConfigBadPort},
}
for _, testCase := range portTests {
obj := testCase.in
err := testCase.out
if validatePort(obj) != err {
t.Logf("did not match expected validation. port %d, err %v", obj.host.port, err)
t.Fail()
}
}
}
func TestValidateSpecifiedFields(t *testing.T) {
specTests := hostQueryTests{
{defaultHostQuery().HostgroupID(1).Port(1), nil},
{defaultHostQuery().HostgroupID(1).Port(1).Port(2), ErrConfigDuplicateSpec},
}
for _, testCase := range specTests {
obj := testCase.in
err := testCase.out
if validateSpecifiedFields(obj) != err {
t.Logf("did not match expected validation. port %v, err %v", obj.specifiedFields, err)
t.Fail()
}
}
}
func TestValidateHostname(t *testing.T) {
hostnameTests := hostQueryTests{
{defaultHostQuery(), ErrConfigNoHostname},
{defaultHostQuery().Hostname("hostname"), nil},
}
for _, testCase := range hostnameTests {
obj := testCase.in
err := testCase.out
if validateHostname(obj) != err {
t.Logf("did not match expected validation. port %s, err %v", obj.host.hostname, err)
t.Fail()
}
}
}
func TestValidateHostQuery(t *testing.T) {
tests := hostQueryTests{
{defaultHostQuery(), nil},
{defaultHostQuery().Table("runtime_mysql_servers"), nil},
{defaultHostQuery().Table("bad table").Port(123), ErrConfigBadTable},
{defaultHostQuery().HostgroupID(1).Port(123).Table("runtime_mysql_servers"), nil},
{defaultHostQuery().HostgroupID(-1), ErrConfigBadHostgroupID},
{defaultHostQuery().HostgroupID(2147483649), ErrConfigBadHostgroupID},
{defaultHostQuery().Port(0), nil},
{defaultHostQuery().Port(65535), nil},
{defaultHostQuery().Port(-1), ErrConfigBadPort},
{defaultHostQuery().Port(65536), ErrConfigBadPort},
{defaultHostQuery().MaxConnections(0), nil},
{defaultHostQuery().MaxConnections(1), nil},
{defaultHostQuery().MaxConnections(-1), ErrConfigBadMaxConnections},
{defaultHostQuery().Status("ONLINE"), nil},
{defaultHostQuery().Status("SHUNNED"), nil},
{defaultHostQuery().Status("OFFLINE_SOFT"), nil},
{defaultHostQuery().Status("OFFLINE_HARD"), nil},
{defaultHostQuery().Status(""), ErrConfigBadStatus},
{defaultHostQuery().Status("status"), ErrConfigBadStatus},
{defaultHostQuery().Weight(0), nil},
{defaultHostQuery().Weight(1), nil},
{defaultHostQuery().Weight(-1), ErrConfigBadWeight},
{defaultHostQuery().Compression(1), nil},
{defaultHostQuery().Compression(-1), ErrConfigBadCompression},
{defaultHostQuery().Compression(102401), ErrConfigBadCompression},
{defaultHostQuery().MaxReplicationLag(1), nil},
{defaultHostQuery().MaxReplicationLag(-1), ErrConfigBadMaxReplicationLag},
{defaultHostQuery().MaxReplicationLag(126144001), ErrConfigBadMaxReplicationLag},
{defaultHostQuery().UseSSL(0), nil},
{defaultHostQuery().UseSSL(1), nil},
{defaultHostQuery().UseSSL(2), ErrConfigBadUseSSL},
{defaultHostQuery().MaxLatencyMS(0), nil},
{defaultHostQuery().MaxLatencyMS(-1), ErrConfigBadMaxLatencyMS},
}
for _, testCase := range tests {
obj := testCase.in
err := testCase.out
if validateHostQuery(obj) != err {
t.Logf("did not match expected validation. obj %v, err %v", obj, err)
t.Fail()
}
}
}
func TestDefaultHostQueryIsValid(t *testing.T) {
if err := validateHostQuery(defaultHostQuery()); err != nil {
t.Fatalf("default query object is not valid: %v", err)
}
}