-
Notifications
You must be signed in to change notification settings - Fork 28
/
config_test.go
62 lines (49 loc) · 1.53 KB
/
config_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
package main
import "testing"
func compareSlices(s1, s2 []int) bool {
if len(s1) == len(s2) {
for i, v := range s1 {
if v != s2[i] {
return false
}
}
} else {
return false
}
return true
}
func TestConfigFile(t *testing.T) {
expected := Configuration{
Listen: "127.0.0.1:3129",
AccessLog: "/tmp/microproxy.access.log",
AuthType: "basic",
AuthRealm: "proxy",
AuthFile: "auth.txt",
ForwardedForHeader: "on",
AllowedConnectPorts: make([]int, 2),
}
expected.AllowedConnectPorts[0] = 443
expected.AllowedConnectPorts[1] = 80
conf := newConfigurationFromFile("microproxy.toml")
if conf.Listen != expected.Listen {
t.Errorf("Got %v, expected %v", conf.Listen, expected.Listen)
}
if conf.AccessLog != expected.AccessLog {
t.Errorf("Got %v, expected %v", conf.AccessLog, expected.AccessLog)
}
if !compareSlices(conf.AllowedConnectPorts, expected.AllowedConnectPorts) {
t.Errorf("Got %v, expected %v", conf.AllowedConnectPorts, expected.AllowedConnectPorts)
}
if conf.AuthFile != expected.AuthFile {
t.Errorf("Got %v, expected %v", conf.AuthFile, expected.AuthFile)
}
if conf.AuthRealm != expected.AuthRealm {
t.Errorf("Got %v, expected %v", conf.AuthRealm, expected.AuthRealm)
}
if conf.AuthType != expected.AuthType {
t.Errorf("Got %v, expected %v", conf.AuthType, expected.AuthType)
}
if conf.ForwardedForHeader != expected.ForwardedForHeader {
t.Errorf("Got %v, expected %v", conf.ForwardedForHeader, expected.ForwardedForHeader)
}
}