-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig_test.go
66 lines (51 loc) · 1.25 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
63
64
65
66
package main
import (
"testing"
"github.com/criteo/http-proxy-exporter/proxyclient"
"github.com/stretchr/testify/assert"
)
func TestLoadConfig(t *testing.T) {
var err error
_, err = loadConfig("config.example.yml")
assert.Nil(t, err, "loadConfig is expected to work on example file, got : %s", err)
_, err = loadConfig("idontexist.yml")
assert.NotNil(t, err, "loadConfig should have returned an error")
}
func TestVerifyConfig(t *testing.T) {
var targets []Target
var errs []error
proxies := []string{
"http://proxy/",
"https://securedproxy/",
}
auth := &proxyclient.AuthMethod{
Type: "basic",
Params: map[string]string{
"Username": "janedoe",
"Password": "Who am I ?",
},
}
target := Target{
URL: "https://www.example.com/",
}
targets = append(targets, target)
config := Config{
AuthMethods: map[string]*proxyclient.AuthMethod{
"basic": auth,
},
Proxies: proxies,
Targets: targets,
}
errs = verifyConfig(&config)
assert.Len(t, errs, 0)
noProxies := config
noProxies.Proxies = []string{}
errs = verifyConfig(&noProxies)
assert.Len(t, errs, 1)
noTargets := config
noTargets.Targets = []Target{}
errs = verifyConfig(&noTargets)
assert.Len(t, errs, 1)
errs = verifyConfig(&Config{})
assert.Len(t, errs, 2)
}