-
Notifications
You must be signed in to change notification settings - Fork 18
/
config_test.go
139 lines (113 loc) · 4.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
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
package main
import (
"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func configTestConfig(stateDirectory string) *Config {
config := testConfig()
config.StateDirectory = stateDirectory
config.DataDirectory = "."
return config
}
func TestConfig(t *testing.T) {
sd := Unwrap(os.MkdirTemp("", "tmp"))
defer os.RemoveAll(sd)
config := configTestConfig(sd)
assert.Nil(t, CleanConfig(config))
config = configTestConfig(sd)
config.BaseURL = "https://drasl.example.com/"
assert.Nil(t, CleanConfig(config))
assert.Equal(t, "https://drasl.example.com", config.BaseURL)
config = configTestConfig(sd)
config.BaseURL = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.BaseURL = ":an invalid URL"
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.DefaultPreferredLanguage = "xx"
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.Domain = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.InstanceName = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.ListenAddress = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.DataDirectory = "/tmp/DraslInvalidDataDirectoryNothingHere"
assert.NotNil(t, CleanConfig(config))
// Missing state directory should be ignored
config = configTestConfig(sd)
config.StateDirectory = "/tmp/DraslInvalidStateDirectoryNothingHere"
assert.Nil(t, CleanConfig(config))
config = configTestConfig(sd)
config.RegistrationExistingPlayer.Allow = true
config.RegistrationExistingPlayer.Nickname = "Example"
config.RegistrationExistingPlayer.SessionURL = "https://drasl.example.com/"
config.RegistrationExistingPlayer.AccountURL = "https://drasl.example.com/"
assert.Nil(t, CleanConfig(config))
assert.Equal(t, "https://drasl.example.com", config.RegistrationExistingPlayer.SessionURL)
assert.Equal(t, "https://drasl.example.com", config.RegistrationExistingPlayer.AccountURL)
config = configTestConfig(sd)
config.RegistrationExistingPlayer.Allow = true
config.RegistrationExistingPlayer.Nickname = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.RegistrationExistingPlayer.Allow = true
config.RegistrationExistingPlayer.SessionURL = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
config.RegistrationExistingPlayer.Allow = true
config.RegistrationExistingPlayer.AccountURL = ""
assert.NotNil(t, CleanConfig(config))
config = configTestConfig(sd)
testFallbackAPIServer := FallbackAPIServer{
Nickname: "Nickname",
SessionURL: "https://drasl.example.com/",
AccountURL: "https://drasl.example.com/",
ServicesURL: "https://drasl.example.com/",
}
fb := testFallbackAPIServer
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.Nil(t, CleanConfig(config))
assert.Equal(t, "https://drasl.example.com", config.FallbackAPIServers[0].SessionURL)
assert.Equal(t, "https://drasl.example.com", config.FallbackAPIServers[0].AccountURL)
assert.Equal(t, "https://drasl.example.com", config.FallbackAPIServers[0].ServicesURL)
fb = testFallbackAPIServer
fb.Nickname = ""
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.SessionURL = ""
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.SessionURL = ":invalid URL"
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.AccountURL = ""
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.AccountURL = ":invalid URL"
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.ServicesURL = ""
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
fb = testFallbackAPIServer
fb.ServicesURL = ":invalid URL"
config.FallbackAPIServers = []FallbackAPIServer{fb}
assert.NotNil(t, CleanConfig(config))
// Test that TEMPLATE_CONFIG_FILE is valid
var templateConfig Config
_, err := toml.Decode(TEMPLATE_CONFIG_FILE, &templateConfig)
assert.Nil(t, err)
}