-
Notifications
You must be signed in to change notification settings - Fork 16
/
readconfig_test.go
259 lines (205 loc) · 6 KB
/
readconfig_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"testing"
"time"
)
type EnvBucket struct {
Items map[string]string
}
func NewEnvBucket() EnvBucket {
return EnvBucket{
Items: make(map[string]string),
}
}
func (e EnvBucket) Getenv(key string) string {
return e.Items[key]
}
func (e EnvBucket) Setenv(key string, value string) {
e.Items[key] = value
}
func TestRead_CombineOutput_DefaultTrue(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := true
if config.combineOutput != want {
t.Logf("combineOutput error, want: %v, got: %v", want, config.combineOutput)
t.Fail()
}
}
func TestRead_CombineOutput_OverrideFalse(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("combine_output", "false")
config := readConfig.Read(defaults)
want := false
if config.combineOutput != want {
t.Logf("combineOutput error, want: %v, got: %v", want, config.combineOutput)
t.Fail()
}
}
func TestRead_CgiHeaders_OverrideFalse(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("cgi_headers", "false")
config := readConfig.Read(defaults)
if config.cgiHeaders != false {
t.Logf("cgiHeaders should have been false (via env)")
t.Fail()
}
}
func TestRead_CgiHeaders_DefaultIsTrueConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
if config.cgiHeaders != true {
t.Logf("cgiHeaders should have been true (unspecified)")
t.Fail()
}
}
func TestRead_WriteDebug_DefaultIsFalseConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
if config.writeDebug != false {
t.Logf("writeDebug should have been false (unspecified)")
t.Fail()
}
}
func TestRead_WriteDebug_TrueOverrideConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("write_debug", "true")
config := readConfig.Read(defaults)
if config.writeDebug != true {
t.Logf("writeDebug should have been true (specified)")
t.Fail()
}
}
func TestRead_WriteDebug_FlaseConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("write_debug", "false")
config := readConfig.Read(defaults)
if config.writeDebug != false {
t.Logf("writeDebug should have been false (specified)")
t.Fail()
}
}
func TestRead_SuppressLockConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("suppress_lock", "true")
config := readConfig.Read(defaults)
if config.suppressLock != true {
t.Logf("suppress_lock envVariable incorrect, got: %s.\n", config.faasProcess)
t.Fail()
}
}
func TestRead_ContentTypeConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("content_type", "application/json")
config := readConfig.Read(defaults)
if config.contentType != "application/json" {
t.Logf("content_type envVariable incorrect, got: %s.\n", config.contentType)
t.Fail()
}
}
func TestRead_FprocessConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("fprocess", "cat")
config := readConfig.Read(defaults)
if config.faasProcess != "cat" {
t.Logf("fprocess envVariable incorrect, got: %s.\n", config.faasProcess)
t.Fail()
}
}
func TestRead_DefaultConfig_Timeouts(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
wantReadTimeout := time.Second * 30
if config.readTimeout != wantReadTimeout {
t.Fatalf("readTimeout want: %v, got: %v", wantReadTimeout, config.readTimeout)
}
wantWriteTimeout := time.Second * 30
if config.writeTimeout != wantWriteTimeout {
t.Fatalf("writeTimeout want: %v, got: %v", wantWriteTimeout, config.writeTimeout)
}
}
func TestRead_DefaultPortConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := 8080
if config.port != want {
t.Logf("port got: %d, want: %d\n", config.port, want)
t.Fail()
}
}
func TestRead_PortConfig(t *testing.T) {
defaults := NewEnvBucket()
defaults.Setenv("port", "8081")
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := 8081
if config.port != want {
t.Logf("port got: %d, want: %d\n", config.port, want)
t.Fail()
}
}
func TestRead_ReadAndWriteTimeoutConfig(t *testing.T) {
defaults := NewEnvBucket()
defaults.Setenv("read_timeout", "10")
defaults.Setenv("write_timeout", "60")
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
if (config.readTimeout) != 10*time.Second {
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
t.Fail()
}
if (config.writeTimeout) != 60*time.Second {
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
t.Fail()
}
}
func TestRead_ReadAndWriteTimeoutDurationConfig(t *testing.T) {
defaults := NewEnvBucket()
defaults.Setenv("read_timeout", "20s")
defaults.Setenv("write_timeout", "1m30s")
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
if (config.readTimeout) != 20*time.Second {
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
t.Fail()
}
if (config.writeTimeout) != 90*time.Second {
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
t.Fail()
}
}
func TestRead_ExecTimeoutConfig(t *testing.T) {
defaults := NewEnvBucket()
defaults.Setenv("exec_timeout", "3s")
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := 3 * time.Second
if (config.execTimeout) != want {
t.Logf("execTimeout incorrect, got: %d - want: %s\n", config.execTimeout, want)
t.Fail()
}
}
func TestRead_MetricsPort(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := 8081
if config.metricsPort != want {
t.Logf("metricsPort incorrect, got: %d - want: %d\n", config.metricsPort, want)
t.Fail()
}
}