Skip to content

Commit 6bc54a6

Browse files
committed
test: add case
1 parent ed1ced7 commit 6bc54a6

File tree

1 file changed

+161
-5
lines changed

1 file changed

+161
-5
lines changed

test/caddy/index.test.ts

Lines changed: 161 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,28 @@ describe('caddy', () => {
4848
4949
test-1.abc.com:80 {
5050
51-
reverse_proxy http://127.0.0.1:8080
51+
reverse_proxy http://127.0.0.1:8080 {
52+
health_uri /
53+
health_interval 2s
54+
health_timeout 5s
55+
fail_duration 2s
56+
unhealthy_status 502 503 504 404
57+
lb_try_duration 3s
58+
lb_try_interval 300ms
59+
health_headers {
60+
Accept text/html
61+
Accept-Encoding gzip, deflate, br
62+
User-Agent Caddy-Health-Check
63+
}
64+
65+
@error status 502 503 504 404
66+
handle_response @error {
67+
respond * 503 {
68+
body "Service Unavailable"
69+
close
70+
}
71+
}
72+
}
5273
}
5374
5475
"
@@ -77,7 +98,28 @@ describe('caddy', () => {
7798
7899
test-2.abc.com {
79100
tls internal
80-
reverse_proxy http://127.0.0.1:8080
101+
reverse_proxy http://127.0.0.1:8080 {
102+
health_uri /
103+
health_interval 2s
104+
health_timeout 5s
105+
fail_duration 2s
106+
unhealthy_status 502 503 504 404
107+
lb_try_duration 3s
108+
lb_try_interval 300ms
109+
health_headers {
110+
Accept text/html
111+
Accept-Encoding gzip, deflate, br
112+
User-Agent Caddy-Health-Check
113+
}
114+
115+
@error status 502 503 504 404
116+
handle_response @error {
117+
respond * 503 {
118+
body "Service Unavailable"
119+
close
120+
}
121+
}
122+
}
81123
}
82124
83125
"
@@ -103,7 +145,28 @@ describe('caddy', () => {
103145
104146
test-3.abc.com:80 {
105147
106-
reverse_proxy http://127.0.0.1:8080
148+
reverse_proxy http://127.0.0.1:8080 {
149+
health_uri /
150+
health_interval 2s
151+
health_timeout 5s
152+
fail_duration 2s
153+
unhealthy_status 502 503 504 404
154+
lb_try_duration 3s
155+
lb_try_interval 300ms
156+
health_headers {
157+
Accept text/html
158+
Accept-Encoding gzip, deflate, br
159+
User-Agent Caddy-Health-Check
160+
}
161+
162+
@error status 502 503 504 404
163+
handle_response @error {
164+
respond * 503 {
165+
body "Service Unavailable"
166+
close
167+
}
168+
}
169+
}
107170
}
108171
109172
"
@@ -128,13 +191,55 @@ describe('caddy', () => {
128191
129192
test-3.abc.com:80 {
130193
131-
reverse_proxy http://127.0.0.1:8080
194+
reverse_proxy http://127.0.0.1:8080 {
195+
health_uri /
196+
health_interval 2s
197+
health_timeout 5s
198+
fail_duration 2s
199+
unhealthy_status 502 503 504 404
200+
lb_try_duration 3s
201+
lb_try_interval 300ms
202+
health_headers {
203+
Accept text/html
204+
Accept-Encoding gzip, deflate, br
205+
User-Agent Caddy-Health-Check
206+
}
207+
208+
@error status 502 503 504 404
209+
handle_response @error {
210+
respond * 503 {
211+
body "Service Unavailable"
212+
close
213+
}
214+
}
215+
}
132216
}
133217
134218
135219
test-4.abc.com {
136220
tls internal
137-
reverse_proxy http://127.0.0.1:8080
221+
reverse_proxy http://127.0.0.1:8080 {
222+
health_uri /
223+
health_interval 2s
224+
health_timeout 5s
225+
fail_duration 2s
226+
unhealthy_status 502 503 504 404
227+
lb_try_duration 3s
228+
lb_try_interval 300ms
229+
health_headers {
230+
Accept text/html
231+
Accept-Encoding gzip, deflate, br
232+
User-Agent Caddy-Health-Check
233+
}
234+
235+
@error status 502 503 504 404
236+
handle_response @error {
237+
respond * 503 {
238+
body "Service Unavailable"
239+
close
240+
}
241+
}
242+
}
138243
}
139244
140245
"
@@ -143,6 +248,57 @@ describe('caddy', () => {
143248
await caddy_443.baseCleanup()
144249
await caddy_80.baseCleanup()
145250
})
251+
252+
test.sequential(':443 with base', async () => {
253+
const caddy = new CaddyInstant()
254+
expect(caddy.checkLock()).toBe(false)
255+
await caddy.run('127.0.0.1:8080', 'test-2.abc.com', {
256+
https: true,
257+
base: '/test/',
258+
})
259+
260+
expect(caddy.checkLock()).toBe(true)
261+
262+
const caddyfile = await caddy.getCaddyfile()
263+
expect(caddyfile).toMatchInlineSnapshot(`
264+
"
265+
{
266+
debug
267+
auto_https disable_redirects
268+
}
269+
270+
271+
test-2.abc.com {
272+
tls internal
273+
reverse_proxy http://127.0.0.1:8080 {
274+
health_uri /test/
275+
health_interval 2s
276+
health_timeout 5s
277+
fail_duration 2s
278+
unhealthy_status 502 503 504 404
279+
lb_try_duration 3s
280+
lb_try_interval 300ms
281+
health_headers {
282+
Accept text/html
283+
Accept-Encoding gzip, deflate, br
284+
User-Agent Caddy-Health-Check
285+
}
286+
287+
@error status 502 503 504 404
288+
handle_response @error {
289+
respond * 503 {
290+
body "Service Unavailable"
291+
close
292+
}
293+
}
294+
}
295+
}
296+
297+
"
298+
`)
299+
300+
await caddy.baseCleanup()
301+
})
146302
})
147303
}, {
148304
timeout: 10000000,

0 commit comments

Comments
 (0)