Skip to content

Commit b1332c0

Browse files
authored
Merge pull request #136 from clue-labs/tests
Clean up and improve structure of integration tests
2 parents 62797fd + c7c8d75 commit b1332c0

File tree

6 files changed

+123
-46
lines changed

6 files changed

+123
-46
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
coverage: none
2121
- run: make
2222
- run: make served
23+
- run: bash tests/await.bash http://clue.localhost/
2324
- run: make test
2425
- run: git config --global user.name "GitHub Actions" && git config --global user.email "[email protected]"
2526
- run: git config --global url."https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ served: build
2121
@echo Container running. Use \"docker rm -f {containerId}\" to stop container.
2222

2323
test:
24-
bash tests/acceptance.sh
24+
bash tests/integration.bash http://clue.localhost/
2525
test -z "$$(git status --porcelain)" || (echo Directory is dirty && git status && exit 1)
2626

2727
deploy:

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ like this:
3434
make test
3535
```
3636

37-
> This test assumes you're running the above web server container on
38-
> `http://clue.localhost`. You may test other deployments like this:
37+
> If you don't want to test this against the local container, you can optionally
38+
> pass in a different base URL like this:
3939
>
4040
> ```bash
41-
> tests/acceptance.sh https://clue.example
41+
> tests/integration.bash http://clue.localhost/
4242
> ```
4343
4444
Once done, you can clean up like this:

tests/acceptance.sh

-42
This file was deleted.

tests/await.bash

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# @copyright Copyright (c) 2024 Christian Lück, taken from https://github.com/clue/framework-x/pull/3 with permission
4+
5+
base=${1:-http://clue.localhost/}
6+
base=${base%/}
7+
8+
for i in {1..600}
9+
do
10+
out=$(curl -v -X PROBE $base/ 2>&1) && exit 0 || echo -n .
11+
sleep 0.1
12+
done
13+
14+
echo
15+
echo "$out"
16+
exit 1

tests/integration.bash

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# run with base url argument like "http://clue.localhost" or "https://user:[email protected]"
4+
base=${1:-http://clue.localhost/}
5+
base=${base%/}
6+
7+
# base url with any userinfo removed
8+
redir=$(echo $base | sed "s,://.*@,://,g")
9+
10+
n=0
11+
curl() {
12+
out=$($(which curl) "$@" 2>&1);
13+
}
14+
match() {
15+
n=$[$n+1]
16+
echo "$out" | grep "$@" >/dev/null && echo -n . || \
17+
(echo ""; echo "Error in test $n: Unable to \"grep $@\" this output:"; echo "$out"; exit 1) || exit 1
18+
}
19+
20+
curl -v $base/
21+
match "HTTP/.* 200"
22+
match -iP "Content-Type: text/html[;\r\n]"
23+
24+
curl -v $base/index.html
25+
match "HTTP/.* 302"
26+
match -iP "Location: $redir/[\r\n]"
27+
28+
curl -v $base/index.html/
29+
match "HTTP/.* 404"
30+
31+
curl -v $base/index
32+
match "HTTP/.* 404"
33+
34+
curl -v $base/blog
35+
match "HTTP/.* 200"
36+
match -iP "Content-Type: text/html[;\r\n]"
37+
38+
curl -v $base/blog.html
39+
match "HTTP/.* 302"
40+
match -iP "Location: $redir/blog[\r\n]"
41+
42+
curl -v $base/blog/
43+
match "HTTP/.* 302"
44+
match -iP "Location: $redir/blog[\r\n]"
45+
46+
curl -v $base/2019
47+
match "HTTP/.* 302"
48+
match -iP "Location: $redir/blog#2019[\r\n]"
49+
50+
curl -v $base/2019/
51+
match "HTTP/.* 302"
52+
match -iP "Location: $redir/blog#2019[\r\n]"
53+
54+
curl -v $base/2000
55+
match "HTTP/.* 404"
56+
57+
curl -v $base/2000/
58+
match "HTTP/.* 404"
59+
60+
curl -v $base/2018/hello-world
61+
match "HTTP/.* 200"
62+
match -iP "Content-Type: text/html[;\r\n]"
63+
64+
curl -v $base/2018/hello-world/
65+
match "HTTP/.* 302"
66+
match -iP "Location: $redir/2018/hello-world[\r\n]"
67+
68+
curl -v $base/contact
69+
match "HTTP/.* 200"
70+
match -iP "Content-Type: text/html[;\r\n]"
71+
72+
curl -v $base/contact -X POST
73+
match "HTTP/.* 400"
74+
75+
curl -v $base/contact --data name=A --data [email protected] --data company=ACME --data budget=None --data message="Let's get in touch!"
76+
match "HTTP/.* 400" # name length
77+
78+
curl -v $base/contact --data name=Alice --data email=alice --data company=ACME --data budget=None --data message="Let's get in touch!"
79+
match "HTTP/.* 400" # email invalid
80+
81+
curl -v $base/contact --data name=Alice --data [email protected] --data company=ACME --data budget=A --data message="Let's get in touch!"
82+
match "HTTP/.* 400" # budget invalid
83+
84+
# curl -v $base/contact --data name=Alice --data [email protected] --data company= --data budget=Yes --data message="Let's get in touch!!"
85+
# match "HTTP/.* 302" # valid without company
86+
87+
# curl -v $base/contact --data name=Alice --data [email protected] --data company=ACME --data budget=Yes --data message="Let's get in touch!!"
88+
# match "HTTP/.* 302" # valid with company
89+
90+
curl -v $base/contact.html
91+
match "HTTP/.* 302"
92+
match -iP "Location: $redir/contact[\r\n]"
93+
94+
curl -v $base/contact.php
95+
match "HTTP/.* 302"
96+
match -iP "Location: $redir/contact[\r\n]"
97+
98+
curl -v $base/contact/
99+
match "HTTP/.* 302"
100+
match -iP "Location: $redir/contact[\r\n]"
101+
102+
echo "OK ($n)"

0 commit comments

Comments
 (0)