Skip to content

Commit 1b4bd3e

Browse files
committed
testing: use Hurl in CI to test Caddy against spec
1 parent 8f87c5d commit 1b4bd3e

File tree

4 files changed

+222
-0
lines changed

4 files changed

+222
-0
lines changed

.github/workflows/ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ on:
77
branches:
88
- master
99
- 2.*
10+
- hurl-tests
1011
pull_request:
1112
branches:
1213
- master
1314
- 2.*
1415

1516
jobs:
1617
test:
18+
permissions:
19+
checks: write
20+
pull-requests: write
1721
strategy:
1822
# Default is true, cancels jobs for other platforms in the matrix if one fails
1923
fail-fast: false
@@ -125,6 +129,31 @@ jobs:
125129
go test -tags nobadger -v -coverprofile="cover-profile.out" -short -race ./...
126130
# echo "status=$?" >> $GITHUB_OUTPUT
127131
132+
- name: Install Hurl
133+
if: matrix.os == 'linux' && matrix.go == '1.22'
134+
run: |
135+
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/4.2.0/hurl_4.2.0_amd64.deb
136+
sudo dpkg -i hurl_4.2.0_amd64.deb
137+
138+
- name: Run Caddy
139+
if: matrix.os == 'linux' && matrix.go == '1.22'
140+
working-directory: ./cmd/caddy
141+
run: |
142+
./caddy start
143+
144+
- name: Run tests with Hurl
145+
if: matrix.os == 'linux' && matrix.go == '1.22'
146+
run: |
147+
mkdir hurl-report
148+
find . -name *.hurl -exec hurl --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \;
149+
150+
- name: Publish Test Results
151+
if: matrix.os == 'linux' && matrix.go == '1.22'
152+
uses: EnricoMi/publish-unit-test-result-action@v2
153+
with:
154+
files: |
155+
hurl-report/junit.xml
156+
128157
# Relevant step if we reinvestigate publishing test/coverage reports
129158
# - name: Prepare coverage reports
130159
# run: |

caddytest/spec/http/headers/spec.hurl

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Configure Caddy
2+
POST http://localhost:2019/load
3+
Content-Type: text/caddyfile
4+
```
5+
{
6+
skip_install_trust
7+
http_port 9080
8+
https_port 9443
9+
local_certs
10+
debug
11+
}
12+
localhost {
13+
header "X-Custom-Header" "Custom-Value"
14+
}
15+
```
16+
17+
GET https://localhost:9443
18+
[Options]
19+
insecure: true
20+
HTTP 200
21+
[Asserts]
22+
header "X-Custom-Header" == "Custom-Value"

caddytest/spec/http/rewrite/spec.hurl

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Configure Caddy
2+
POST http://localhost:2019/load
3+
User-Agent: hurl/ci
4+
Content-Type: text/caddyfile
5+
```
6+
{
7+
skip_install_trust
8+
http_port 9080
9+
https_port 9443
10+
local_certs
11+
}
12+
localhost {
13+
rewrite /from /to
14+
respond {uri}
15+
}
16+
```
17+
18+
# simple scenario: rewriting /from to /to produces expected result of seeing /to
19+
GET https://localhost:9443/from
20+
[Options]
21+
insecure: true
22+
HTTP 200
23+
[Asserts]
24+
body == "/to"
25+
26+
# unmatched path is passed through unchanged
27+
GET https://localhost:9443
28+
[Options]
29+
insecure: true
30+
HTTP 200
31+
[Asserts]
32+
body == "/"
33+
34+
# having a query parameter does not trip the rewrite and retains the query
35+
GET https://localhost:9443/from?query_param=value
36+
[Options]
37+
insecure: true
38+
HTTP 200
39+
[Asserts]
40+
body == "/to?query_param=value"
41+
42+
43+
# Configure Caddy
44+
POST http://localhost:2019/load
45+
User-Agent: hurl/ci
46+
Content-Type: text/caddyfile
47+
```
48+
{
49+
skip_install_trust
50+
http_port 9080
51+
https_port 9443
52+
local_certs
53+
}
54+
localhost {
55+
rewrite /from /to?a=b
56+
respond {uri}
57+
}
58+
```
59+
60+
# a rewrite with query parameters affects the parameters
61+
GET https://localhost:9443/from?query_param=value
62+
[Options]
63+
insecure: true
64+
HTTP 200
65+
[Asserts]
66+
body == "/to?a=b"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Configure Caddy
2+
POST http://localhost:2019/load
3+
User-Agent: hurl/ci
4+
Content-Type: text/caddyfile
5+
```
6+
{
7+
skip_install_trust
8+
http_port 9080
9+
https_port 9443
10+
local_certs
11+
}
12+
localhost {
13+
log
14+
respond "Hello, World!"
15+
}
16+
```
17+
18+
GET https://localhost:9443
19+
[Options]
20+
insecure: true
21+
HTTP 200
22+
[Asserts]
23+
`Hello, World!`
24+
25+
26+
GET https://localhost:9443/foo
27+
[Options]
28+
insecure: true
29+
HTTP 200
30+
[Asserts]
31+
`Hello, World!`
32+
33+
# Configure Caddy
34+
POST http://localhost:2019/load
35+
User-Agent: hurl/ci
36+
Content-Type: text/caddyfile
37+
```
38+
{
39+
skip_install_trust
40+
http_port 9080
41+
https_port 9443
42+
local_certs
43+
}
44+
localhost {
45+
respond "New text!"
46+
}
47+
```
48+
49+
GET https://localhost:9443
50+
[Options]
51+
insecure: true
52+
HTTP/2 200
53+
[Asserts]
54+
`New text!`
55+
56+
57+
GET https://localhost:9443/foo
58+
[Options]
59+
insecure: true
60+
HTTP/2 200
61+
[Asserts]
62+
`New text!`
63+
64+
GET https://localhost:9443/foo
65+
[Options]
66+
insecure: true
67+
HTTP/2 200
68+
[Asserts]
69+
body != "Hello, World!"
70+
71+
# Configure Caddy
72+
# The body is a placeholder
73+
POST http://localhost:2019/load
74+
User-Agent: hurl/ci
75+
Content-Type: text/caddyfile
76+
```
77+
{
78+
skip_install_trust
79+
http_port 9080
80+
https_port 9443
81+
local_certs
82+
}
83+
localhost {
84+
log
85+
respond {http.request.body}
86+
}
87+
```
88+
89+
# handler responds with the "application/json" if the response body is valid JSON
90+
POST https://localhost:9443
91+
[Options]
92+
insecure: true
93+
```json
94+
{
95+
"greeting": "Hello, world!"
96+
}
97+
```
98+
HTTP/2 200
99+
[Asserts]
100+
header "Content-Type" == "application/json"
101+
```json
102+
{
103+
"greeting": "Hello, world!"
104+
}
105+
```

0 commit comments

Comments
 (0)