-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
80 lines (64 loc) · 2.15 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"os"
"strings"
"testing"
)
func TestLoadingConfigFromFile(t *testing.T) {
sampleConfigFile, _ := os.Open("test/config.json")
defer sampleConfigFile.Close()
sampleConfig, _ := NewConfigFromReader(sampleConfigFile)
if err := sampleConfig.Validate(); err != nil {
t.Fatal("Expected config to be valid but found: ", err)
}
if sampleConfig.Port != 26000 {
t.Fatal("Expected port to be 26000 but found:", sampleConfig.Port)
}
if sampleConfig.DialTimeout != 10 {
t.Fatal("Expected port to be 10 but found:", sampleConfig.DialTimeout)
}
if !sampleConfig.StripProxyHeaders {
t.Fatal("Expected sampleConfig.StripProxyHeaders to be true")
}
if sampleConfig.UseIncomingLocalAddr {
t.Fatal("Expected sampleConfig.UseIncomingLocalAddr to be false")
}
if !sampleConfig.AuthenticationRequired() {
t.Fatal("Expected sample config to require authentication")
}
credentialsLen := len(sampleConfig.Credentials)
if credentialsLen != 2 {
t.Fatal("Expected config to have 2 credentials but found:", credentialsLen)
}
credential := Credential{Username: "login", Password: "yolo"}
if sampleConfig.Credentials[0] != credential {
t.Fatal("Expected", credential, "but found", sampleConfig.Credentials[0])
}
credential = Credential{Username: "ron.swanson", Password: "g0ld5topsTheGovt"}
if sampleConfig.Credentials[1] != credential {
t.Fatal("Expected", credential, "but found", sampleConfig.Credentials[1])
}
}
func TestInvalidConfigFormat(t *testing.T) {
invalidFormatReader := strings.NewReader(`{"testing":"ok...`)
_, err := NewConfigFromReader(invalidFormatReader)
if err == nil {
t.Fatal("Config should have returned an error for being invalid json")
}
}
func TestConfigInavlidUsername(t *testing.T) {
sampleConfig := &Config{
Credentials: []Credential{{Username: "", Password: "test"}},
}
if sampleConfig.Validate() != InvalidCredentials {
t.Fatal("Expected username to be invalid")
}
}
func TestConfigInavlidPassword(t *testing.T) {
sampleConfig := &Config{
Credentials: []Credential{{Username: "test", Password: ""}},
}
if sampleConfig.Validate() != InvalidCredentials {
t.Fatal("Expected password to be invalid")
}
}