@marcel91200 / caddy Mirror · read-only / commits / bde3823b
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddytest: Refactor Caddyfile adapt tests to separate files (#3398)

Francis Lavoie committed May 14, 2020 at 17:53 UTC bde3823b76b457a933e684cd096ca84fc6378997
12 files changed +592 -573
caddytest/caddytest.go
+15 -6
@@ -321,13 +321,13 @@ func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, e
321 return resp
322 }
323
324 -// AssertAdapt adapts a config and then tests it against an expected result
325 -func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) {
324 +// CompareAdapt adapts a config and then compares it against an expected result
325 +func CompareAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) bool {
326
327 cfgAdapter := caddyconfig.GetAdapter(adapterName)
328 if cfgAdapter == nil {
329 - t.Errorf("unrecognized config adapter '%s'", adapterName)
330 - return
329 + t.Logf("unrecognized config adapter '%s'", adapterName)
330 + return false
331 }
332
333 options := make(map[string]interface{})
@@ -335,8 +335,8 @@ func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedRes
335
336 result, warnings, err := cfgAdapter.Adapt([]byte(rawConfig), options)
337 if err != nil {
338 - t.Errorf("adapting config using %s adapter: %v", adapterName, err)
339 - return
338 + t.Logf("adapting config using %s adapter: %v", adapterName, err)
339 + return false
340 }
341
342 if len(warnings) > 0 {
@@ -369,6 +369,15 @@ func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedRes
369 fmt.Printf(" + %s\n", d.Payload)
370 }
371 }
372 + return false
373 + }
374 + return true
375 +}
376 +
377 +// AssertAdapt adapts a config and then tests it against an expected result
378 +func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) {
379 + ok := CompareAdapt(t, rawConfig, adapterName, expectedResponse)
380 + if !ok {
381 t.Fail()
382 }
383 }
caddytest/integration/caddyfile_adapt/global_options.txt new
+71
@@ -0,0 +1,71 @@
1 +{
2 + debug
3 + http_port 8080
4 + https_port 8443
5 + default_sni localhost
6 + order root first
7 + storage file_system {
8 + root /data
9 + }
10 + acme_ca https://example.com
11 + acme_ca_root /path/to/ca.crt
12 + email test@example.com
13 + admin off
14 + on_demand_tls {
15 + ask https://example.com
16 + interval 30s
17 + burst 20
18 + }
19 + local_certs
20 + key_type ed25519
21 +}
22 +
23 +:80
24 +----------
25 +{
26 + "admin": {
27 + "disabled": true
28 + },
29 + "logging": {
30 + "logs": {
31 + "default": {
32 + "level": "DEBUG"
33 + }
34 + }
35 + },
36 + "storage": {
37 + "module": "file_system",
38 + "root": "/data"
39 + },
40 + "apps": {
41 + "http": {
42 + "http_port": 8080,
43 + "https_port": 8443,
44 + "servers": {
45 + "srv0": {
46 + "listen": [
47 + ":80"
48 + ]
49 + }
50 + }
51 + },
52 + "tls": {
53 + "automation": {
54 + "policies": [
55 + {
56 + "issuer": {
57 + "module": "internal"
58 + }
59 + }
60 + ],
61 + "on_demand": {
62 + "rate_limit": {
63 + "interval": 30000000000,
64 + "burst": 20
65 + },
66 + "ask": "https://example.com"
67 + }
68 + }
69 + }
70 + }
71 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/http_only_on_any_address.txt new
+37
@@ -0,0 +1,37 @@
1 +:80 {
2 + respond /version 200 {
3 + body "hello from localhost"
4 + }
5 +}
6 +----------
7 +{
8 + "apps": {
9 + "http": {
10 + "servers": {
11 + "srv0": {
12 + "listen": [
13 + ":80"
14 + ],
15 + "routes": [
16 + {
17 + "match": [
18 + {
19 + "path": [
20 + "/version"
21 + ]
22 + }
23 + ],
24 + "handle": [
25 + {
26 + "body": "hello from localhost",
27 + "handler": "static_response",
28 + "status_code": 200
29 + }
30 + ]
31 + }
32 + ]
33 + }
34 + }
35 + }
36 + }
37 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/http_only_on_domain.txt new
+59
@@ -0,0 +1,59 @@
1 +http://a.caddy.localhost {
2 + respond /version 200 {
3 + body "hello from localhost"
4 + }
5 +}
6 +----------
7 +{
8 + "apps": {
9 + "http": {
10 + "servers": {
11 + "srv0": {
12 + "listen": [
13 + ":80"
14 + ],
15 + "routes": [
16 + {
17 + "match": [
18 + {
19 + "host": [
20 + "a.caddy.localhost"
21 + ]
22 + }
23 + ],
24 + "handle": [
25 + {
26 + "handler": "subroute",
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "body": "hello from localhost",
32 + "handler": "static_response",
33 + "status_code": 200
34 + }
35 + ],
36 + "match": [
37 + {
38 + "path": [
39 + "/version"
40 + ]
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + ],
47 + "terminal": true
48 + }
49 + ],
50 + "automatic_https": {
51 + "skip": [
52 + "a.caddy.localhost"
53 + ]
54 + }
55 + }
56 + }
57 + }
58 + }
59 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/http_only_on_localhost.txt new
+54
@@ -0,0 +1,54 @@
1 +localhost:80 {
2 + respond /version 200 {
3 + body "hello from localhost"
4 + }
5 +}
6 +----------
7 +{
8 + "apps": {
9 + "http": {
10 + "servers": {
11 + "srv0": {
12 + "listen": [
13 + ":80"
14 + ],
15 + "routes": [
16 + {
17 + "match": [
18 + {
19 + "host": [
20 + "localhost"
21 + ]
22 + }
23 + ],
24 + "handle": [
25 + {
26 + "handler": "subroute",
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "body": "hello from localhost",
32 + "handler": "static_response",
33 + "status_code": 200
34 + }
35 + ],
36 + "match": [
37 + {
38 + "path": [
39 + "/version"
40 + ]
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + ],
47 + "terminal": true
48 + }
49 + ]
50 + }
51 + }
52 + }
53 + }
54 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/http_only_on_non_standard_port.txt new
+59
@@ -0,0 +1,59 @@
1 +http://a.caddy.localhost:81 {
2 + respond /version 200 {
3 + body "hello from localhost"
4 + }
5 +}
6 +----------
7 +{
8 + "apps": {
9 + "http": {
10 + "servers": {
11 + "srv0": {
12 + "listen": [
13 + ":81"
14 + ],
15 + "routes": [
16 + {
17 + "match": [
18 + {
19 + "host": [
20 + "a.caddy.localhost"
21 + ]
22 + }
23 + ],
24 + "handle": [
25 + {
26 + "handler": "subroute",
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "body": "hello from localhost",
32 + "handler": "static_response",
33 + "status_code": 200
34 + }
35 + ],
36 + "match": [
37 + {
38 + "path": [
39 + "/version"
40 + ]
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + ],
47 + "terminal": true
48 + }
49 + ],
50 + "automatic_https": {
51 + "skip": [
52 + "a.caddy.localhost"
53 + ]
54 + }
55 + }
56 + }
57 + }
58 + }
59 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/https_on_domain.txt new
+54
@@ -0,0 +1,54 @@
1 +a.caddy.localhost {
2 + respond /version 200 {
3 + body "hello from localhost"
4 + }
5 +}
6 +----------
7 +{
8 + "apps": {
9 + "http": {
10 + "servers": {
11 + "srv0": {
12 + "listen": [
13 + ":443"
14 + ],
15 + "routes": [
16 + {
17 + "match": [
18 + {
19 + "host": [
20 + "a.caddy.localhost"
21 + ]
22 + }
23 + ],
24 + "handle": [
25 + {
26 + "handler": "subroute",
27 + "routes": [
28 + {
29 + "handle": [
30 + {
31 + "body": "hello from localhost",
32 + "handler": "static_response",
33 + "status_code": 200
34 + }
35 + ],
36 + "match": [
37 + {
38 + "path": [
39 + "/version"
40 + ]
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + ],
47 + "terminal": true
48 + }
49 + ]
50 + }
51 + }
52 + }
53 + }
54 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/log_roll_days.txt new
+47
@@ -0,0 +1,47 @@
1 +:80
2 +
3 +log {
4 + output file /var/log/access.log {
5 + roll_size 1gb
6 + roll_keep 5
7 + roll_keep_for 90d
8 + }
9 +}
10 +----------
11 +{
12 + "logging": {
13 + "logs": {
14 + "default": {
15 + "exclude": [
16 + "http.log.access.log0"
17 + ]
18 + },
19 + "log0": {
20 + "writer": {
21 + "filename": "/var/log/access.log",
22 + "output": "file",
23 + "roll_keep": 5,
24 + "roll_keep_days": 90,
25 + "roll_size_mb": 954
26 + },
27 + "include": [
28 + "http.log.access.log0"
29 + ]
30 + }
31 + }
32 + },
33 + "apps": {
34 + "http": {
35 + "servers": {
36 + "srv0": {
37 + "listen": [
38 + ":80"
39 + ],
40 + "logs": {
41 + "default_logger_name": "log0"
42 + }
43 + }
44 + }
45 + }
46 + }
47 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/matcher_syntax.txt new
+77
@@ -0,0 +1,77 @@
1 +:80 {
2 + @matcher {
3 + method GET
4 + }
5 + respond @matcher "get"
6 +
7 + @matcher2 method POST
8 + respond @matcher2 "post"
9 +
10 + @matcher3 not method PUT
11 + respond @matcher3 "not put"
12 +}
13 +----------
14 +{
15 + "apps": {
16 + "http": {
17 + "servers": {
18 + "srv0": {
19 + "listen": [
20 + ":80"
21 + ],
22 + "routes": [
23 + {
24 + "match": [
25 + {
26 + "method": [
27 + "GET"
28 + ]
29 + }
30 + ],
31 + "handle": [
32 + {
33 + "body": "get",
34 + "handler": "static_response"
35 + }
36 + ]
37 + },
38 + {
39 + "match": [
40 + {
41 + "method": [
42 + "POST"
43 + ]
44 + }
45 + ],
46 + "handle": [
47 + {
48 + "body": "post",
49 + "handler": "static_response"
50 + }
51 + ]
52 + },
53 + {
54 + "match": [
55 + {
56 + "not": [
57 + {
58 + "method": [
59 + "PUT"
60 + ]
61 + }
62 + ]
63 + }
64 + ],
65 + "handle": [
66 + {
67 + "body": "not put",
68 + "handler": "static_response"
69 + }
70 + ]
71 + }
72 + ]
73 + }
74 + }
75 + }
76 + }
77 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/not_block_merging.txt new
+49
@@ -0,0 +1,49 @@
1 +:80
2 +
3 +@test {
4 + not {
5 + header Abc "123"
6 + header Bcd "123"
7 + }
8 +}
9 +respond @test 403
10 +----------
11 +{
12 + "apps": {
13 + "http": {
14 + "servers": {
15 + "srv0": {
16 + "listen": [
17 + ":80"
18 + ],
19 + "routes": [
20 + {
21 + "match": [
22 + {
23 + "not": [
24 + {
25 + "header": {
26 + "Abc": [
27 + "123"
28 + ],
29 + "Bcd": [
30 + "123"
31 + ]
32 + }
33 + }
34 + ]
35 + }
36 + ],
37 + "handle": [
38 + {
39 + "handler": "static_response",
40 + "status_code": 403
41 + }
42 + ]
43 + }
44 + ]
45 + }
46 + }
47 + }
48 + }
49 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.txt new
+43
@@ -0,0 +1,43 @@
1 +localhost:80
2 +respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
3 +----------
4 +{
5 + "apps": {
6 + "http": {
7 + "servers": {
8 + "srv0": {
9 + "listen": [
10 + ":80"
11 + ],
12 + "routes": [
13 + {
14 + "match": [
15 + {
16 + "host": [
17 + "localhost"
18 + ]
19 + }
20 + ],
21 + "handle": [
22 + {
23 + "handler": "subroute",
24 + "routes": [
25 + {
26 + "handle": [
27 + {
28 + "body": "{http.request.header.content-type} {http.request.host.labels.0} {http.request.uri.query.p} {http.request.uri.path.0} {http.regexp.name.0}",
29 + "handler": "static_response"
30 + }
31 + ]
32 + }
33 + ]
34 + }
35 + ],
36 + "terminal": true
37 + }
38 + ]
39 + }
40 + }
41 + }
42 + }
43 +}
\ No newline at end of file
caddytest/integration/caddyfile_adapt_test.go
+27 -567
@@ -1,587 +1,47 @@
1 package integration
2
3 import (
4 + "io/ioutil"
5 + "regexp"
6 + "strings"
7 "testing"
8
9 "github.com/caddyserver/caddy/v2/caddytest"
10 )
11
9 -func TestHttpOnlyOnLocalhost(t *testing.T) {
10 - caddytest.AssertAdapt(t, `
11 - localhost:80 {
12 - respond /version 200 {
13 - body "hello from localhost"
14 - }
15 - }
16 - `, "caddyfile", `{
17 - "apps": {
18 - "http": {
19 - "servers": {
20 - "srv0": {
21 - "listen": [
22 - ":80"
23 - ],
24 - "routes": [
25 - {
26 - "match": [
27 - {
28 - "host": [
29 - "localhost"
30 - ]
31 - }
32 - ],
33 - "handle": [
34 - {
35 - "handler": "subroute",
36 - "routes": [
37 - {
38 - "handle": [
39 - {
40 - "body": "hello from localhost",
41 - "handler": "static_response",
42 - "status_code": 200
43 - }
44 - ],
45 - "match": [
46 - {
47 - "path": [
48 - "/version"
49 - ]
50 - }
51 - ]
52 - }
53 - ]
54 - }
55 - ],
56 - "terminal": true
57 - }
58 - ]
59 - }
60 - }
61 - }
12 +func TestCaddyfileAdaptToJSON(t *testing.T) {
13 + // load the list of test files from the dir
14 + files, err := ioutil.ReadDir("./caddyfile_adapt")
15 + if err != nil {
16 + t.Errorf("failed to read caddyfile_adapt dir: %s", err)
17 }
63 -}`)
64 -}
18
66 -func TestHttpOnlyOnAnyAddress(t *testing.T) {
67 - caddytest.AssertAdapt(t, `
68 - :80 {
69 - respond /version 200 {
70 - body "hello from localhost"
71 - }
72 - }
73 - `, "caddyfile", `{
74 - "apps": {
75 - "http": {
76 - "servers": {
77 - "srv0": {
78 - "listen": [
79 - ":80"
80 - ],
81 - "routes": [
82 - {
83 - "match": [
84 - {
85 - "path": [
86 - "/version"
87 - ]
88 - }
89 - ],
90 - "handle": [
91 - {
92 - "body": "hello from localhost",
93 - "handler": "static_response",
94 - "status_code": 200
95 - }
96 - ]
97 - }
98 - ]
99 - }
100 - }
101 - }
102 - }
103 -}`)
104 -}
19 + // prep a regexp to fix strings on windows
20 + winNewlines := regexp.MustCompile(`\r?\n`)
21
106 -func TestHttpsOnDomain(t *testing.T) {
107 - caddytest.AssertAdapt(t, `
108 - a.caddy.localhost {
109 - respond /version 200 {
110 - body "hello from localhost"
111 - }
112 - }
113 - `, "caddyfile", `{
114 - "apps": {
115 - "http": {
116 - "servers": {
117 - "srv0": {
118 - "listen": [
119 - ":443"
120 - ],
121 - "routes": [
122 - {
123 - "match": [
124 - {
125 - "host": [
126 - "a.caddy.localhost"
127 - ]
128 - }
129 - ],
130 - "handle": [
131 - {
132 - "handler": "subroute",
133 - "routes": [
134 - {
135 - "handle": [
136 - {
137 - "body": "hello from localhost",
138 - "handler": "static_response",
139 - "status_code": 200
140 - }
141 - ],
142 - "match": [
143 - {
144 - "path": [
145 - "/version"
146 - ]
147 - }
148 - ]
149 - }
150 - ]
151 - }
152 - ],
153 - "terminal": true
154 - }
155 - ]
156 - }
157 - }
22 + for _, f := range files {
23 + if f.IsDir() {
24 + continue
25 }
159 - }
160 -}`)
161 -}
26
163 -func TestHttpOnlyOnDomain(t *testing.T) {
164 - caddytest.AssertAdapt(t, `
165 - http://a.caddy.localhost {
166 - respond /version 200 {
167 - body "hello from localhost"
27 + // read the test file
28 + filename := f.Name()
29 + data, err := ioutil.ReadFile("./caddyfile_adapt/" + filename)
30 + if err != nil {
31 + t.Errorf("failed to read %s dir: %s", filename, err)
32 }
169 - }
170 - `, "caddyfile", `{
171 - "apps": {
172 - "http": {
173 - "servers": {
174 - "srv0": {
175 - "listen": [
176 - ":80"
177 - ],
178 - "routes": [
179 - {
180 - "match": [
181 - {
182 - "host": [
183 - "a.caddy.localhost"
184 - ]
185 - }
186 - ],
187 - "handle": [
188 - {
189 - "handler": "subroute",
190 - "routes": [
191 - {
192 - "handle": [
193 - {
194 - "body": "hello from localhost",
195 - "handler": "static_response",
196 - "status_code": 200
197 - }
198 - ],
199 - "match": [
200 - {
201 - "path": [
202 - "/version"
203 - ]
204 - }
205 - ]
206 - }
207 - ]
208 - }
209 - ],
210 - "terminal": true
211 - }
212 - ],
213 - "automatic_https": {
214 - "skip": [
215 - "a.caddy.localhost"
216 - ]
217 - }
218 - }
219 - }
220 - }
221 - }
222 -}`)
223 -}
33
225 -func TestHttpOnlyOnNonStandardPort(t *testing.T) {
226 - caddytest.AssertAdapt(t, `
227 - http://a.caddy.localhost:81 {
228 - respond /version 200 {
229 - body "hello from localhost"
230 - }
231 - }
232 - `, "caddyfile", `{
233 - "apps": {
234 - "http": {
235 - "servers": {
236 - "srv0": {
237 - "listen": [
238 - ":81"
239 - ],
240 - "routes": [
241 - {
242 - "match": [
243 - {
244 - "host": [
245 - "a.caddy.localhost"
246 - ]
247 - }
248 - ],
249 - "handle": [
250 - {
251 - "handler": "subroute",
252 - "routes": [
253 - {
254 - "handle": [
255 - {
256 - "body": "hello from localhost",
257 - "handler": "static_response",
258 - "status_code": 200
259 - }
260 - ],
261 - "match": [
262 - {
263 - "path": [
264 - "/version"
265 - ]
266 - }
267 - ]
268 - }
269 - ]
270 - }
271 - ],
272 - "terminal": true
273 - }
274 - ],
275 - "automatic_https": {
276 - "skip": [
277 - "a.caddy.localhost"
278 - ]
279 - }
280 - }
281 - }
282 - }
283 - }
284 -}`)
285 -}
286 -
287 -func TestMatcherSyntax(t *testing.T) {
288 - caddytest.AssertAdapt(t, `
289 - :80 {
290 - @matcher {
291 - method GET
292 - }
293 - respond @matcher "get"
34 + // split the Caddyfile (first) and JSON (second) parts
35 + parts := strings.Split(string(data), "----------")
36 + caddyfile, json := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
37
295 - @matcher2 method POST
296 - respond @matcher2 "post"
297 -
298 - @matcher3 not method PUT
299 - respond @matcher3 "not put"
300 - }
301 - `, "caddyfile", `{
302 - "apps": {
303 - "http": {
304 - "servers": {
305 - "srv0": {
306 - "listen": [
307 - ":80"
308 - ],
309 - "routes": [
310 - {
311 - "match": [
312 - {
313 - "method": [
314 - "GET"
315 - ]
316 - }
317 - ],
318 - "handle": [
319 - {
320 - "body": "get",
321 - "handler": "static_response"
322 - }
323 - ]
324 - },
325 - {
326 - "match": [
327 - {
328 - "method": [
329 - "POST"
330 - ]
331 - }
332 - ],
333 - "handle": [
334 - {
335 - "body": "post",
336 - "handler": "static_response"
337 - }
338 - ]
339 - },
340 - {
341 - "match": [
342 - {
343 - "not": [
344 - {
345 - "method": [
346 - "PUT"
347 - ]
348 - }
349 - ]
350 - }
351 - ],
352 - "handle": [
353 - {
354 - "body": "not put",
355 - "handler": "static_response"
356 - }
357 - ]
358 - }
359 - ]
360 - }
361 - }
362 - }
363 - }
364 -}`)
365 -}
366 -
367 -func TestNotBlockMerging(t *testing.T) {
368 - caddytest.AssertAdapt(t, `
369 - :80
370 -
371 - @test {
372 - not {
373 - header Abc "123"
374 - header Bcd "123"
375 - }
376 - }
377 - respond @test 403
378 - `, "caddyfile", `{
379 - "apps": {
380 - "http": {
381 - "servers": {
382 - "srv0": {
383 - "listen": [
384 - ":80"
385 - ],
386 - "routes": [
387 - {
388 - "match": [
389 - {
390 - "not": [
391 - {
392 - "header": {
393 - "Abc": [
394 - "123"
395 - ],
396 - "Bcd": [
397 - "123"
398 - ]
399 - }
400 - }
401 - ]
402 - }
403 - ],
404 - "handle": [
405 - {
406 - "handler": "static_response",
407 - "status_code": 403
408 - }
409 - ]
410 - }
411 - ]
412 - }
413 - }
414 - }
415 - }
416 -}`)
417 -}
418 -
419 -func TestGlobalOptions(t *testing.T) {
420 - caddytest.AssertAdapt(t, `
421 - {
422 - debug
423 - http_port 8080
424 - https_port 8443
425 - default_sni localhost
426 - order root first
427 - storage file_system {
428 - root /data
429 - }
430 - acme_ca https://example.com
431 - acme_ca_root /path/to/ca.crt
432 - email test@example.com
433 - admin off
434 - on_demand_tls {
435 - ask https://example.com
436 - interval 30s
437 - burst 20
438 - }
439 - local_certs
440 - key_type ed25519
441 - }
442 -
443 - :80
444 - `, "caddyfile", `{
445 - "admin": {
446 - "disabled": true
447 - },
448 - "logging": {
449 - "logs": {
450 - "default": {
451 - "level": "DEBUG"
452 - }
453 - }
454 - },
455 - "storage": {
456 - "module": "file_system",
457 - "root": "/data"
458 - },
459 - "apps": {
460 - "http": {
461 - "http_port": 8080,
462 - "https_port": 8443,
463 - "servers": {
464 - "srv0": {
465 - "listen": [
466 - ":80"
467 - ]
468 - }
469 - }
470 - },
471 - "tls": {
472 - "automation": {
473 - "policies": [
474 - {
475 - "issuer": {
476 - "module": "internal"
477 - }
478 - }
479 - ],
480 - "on_demand": {
481 - "rate_limit": {
482 - "interval": 30000000000,
483 - "burst": 20
484 - },
485 - "ask": "https://example.com"
486 - }
487 - }
488 - }
489 - }
490 -}`)
491 -}
492 -
493 -func TestLogRollDays(t *testing.T) {
494 - caddytest.AssertAdapt(t, `
495 - :80
496 -
497 - log {
498 - output file /var/log/access.log {
499 - roll_size 1gb
500 - roll_keep 5
501 - roll_keep_for 90d
502 - }
503 - }
504 - `, "caddyfile", `{
505 - "logging": {
506 - "logs": {
507 - "default": {
508 - "exclude": [
509 - "http.log.access.log0"
510 - ]
511 - },
512 - "log0": {
513 - "writer": {
514 - "filename": "/var/log/access.log",
515 - "output": "file",
516 - "roll_keep": 5,
517 - "roll_keep_days": 90,
518 - "roll_size_mb": 954
519 - },
520 - "include": [
521 - "http.log.access.log0"
522 - ]
523 - }
524 - }
525 - },
526 - "apps": {
527 - "http": {
528 - "servers": {
529 - "srv0": {
530 - "listen": [
531 - ":80"
532 - ],
533 - "logs": {
534 - "default_logger_name": "log0"
535 - }
536 - }
537 - }
538 - }
539 - }
540 -}`)
541 -}
38 + // replace windows newlines in the json with unix newlines
39 + json = winNewlines.ReplaceAllString(json, "\n")
40
543 -func TestShorthandParameterizedPlaceholders(t *testing.T) {
544 - caddytest.AssertAdapt(t, `
545 - localhost:80
546 - respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
547 - `, "caddyfile", `{
548 - "apps": {
549 - "http": {
550 - "servers": {
551 - "srv0": {
552 - "listen": [
553 - ":80"
554 - ],
555 - "routes": [
556 - {
557 - "match": [
558 - {
559 - "host": [
560 - "localhost"
561 - ]
562 - }
563 - ],
564 - "handle": [
565 - {
566 - "handler": "subroute",
567 - "routes": [
568 - {
569 - "handle": [
570 - {
571 - "body": "{http.request.header.content-type} {http.request.host.labels.0} {http.request.uri.query.p} {http.request.uri.path.0} {http.regexp.name.0}",
572 - "handler": "static_response"
573 - }
574 - ]
575 - }
576 - ]
577 - }
578 - ],
579 - "terminal": true
580 - }
581 - ]
582 - }
583 - }
41 + // run the test
42 + ok := caddytest.CompareAdapt(t, caddyfile, "caddyfile", json)
43 + if !ok {
44 + t.Errorf("failed to adapt %s", filename)
45 }
46 }
586 -}`)
47 }