Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and improve structure of integration tests #136

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
coverage: none
- run: make
- run: make served
- run: bash tests/await.bash http://clue.localhost/
- run: make test
- run: git config --global user.name "GitHub Actions" && git config --global user.email "actions@github.com"
- run: git config --global url."https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ served: build
@echo Container running. Use \"docker rm -f {containerId}\" to stop container.

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

deploy:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ like this:
make test
```

> This test assumes you're running the above web server container on
> `http://clue.localhost`. You may test other deployments like this:
> If you don't want to test this against the local container, you can optionally
> pass in a different base URL like this:
>
> ```bash
> tests/acceptance.sh https://clue.example
> tests/integration.bash http://clue.localhost/
> ```

Once done, you can clean up like this:
Expand Down
42 changes: 0 additions & 42 deletions tests/acceptance.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tests/await.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# @copyright Copyright (c) 2024 Christian Lück, taken from https://github.com/clue/framework-x/pull/3 with permission

base=${1:-http://clue.localhost/}
base=${base%/}

for i in {1..600}
do
out=$(curl -v -X PROBE $base/ 2>&1) && exit 0 || echo -n .
sleep 0.1
done

echo
echo "$out"
exit 1
102 changes: 102 additions & 0 deletions tests/integration.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

# run with base url argument like "http://clue.localhost" or "https://user:pass@clue.example"
base=${1:-http://clue.localhost/}
base=${base%/}

# base url with any userinfo removed
redir=$(echo $base | sed "s,://.*@,://,g")

n=0
curl() {
out=$($(which curl) "$@" 2>&1);
}
match() {
n=$[$n+1]
echo "$out" | grep "$@" >/dev/null && echo -n . || \
(echo ""; echo "Error in test $n: Unable to \"grep $@\" this output:"; echo "$out"; exit 1) || exit 1
}

curl -v $base/
match "HTTP/.* 200"
match -iP "Content-Type: text/html[;\r\n]"

curl -v $base/index.html
match "HTTP/.* 302"
match -iP "Location: $redir/[\r\n]"

curl -v $base/index.html/
match "HTTP/.* 404"

curl -v $base/index
match "HTTP/.* 404"

curl -v $base/blog
match "HTTP/.* 200"
match -iP "Content-Type: text/html[;\r\n]"

curl -v $base/blog.html
match "HTTP/.* 302"
match -iP "Location: $redir/blog[\r\n]"

curl -v $base/blog/
match "HTTP/.* 302"
match -iP "Location: $redir/blog[\r\n]"

curl -v $base/2019
match "HTTP/.* 302"
match -iP "Location: $redir/blog#2019[\r\n]"

curl -v $base/2019/
match "HTTP/.* 302"
match -iP "Location: $redir/blog#2019[\r\n]"

curl -v $base/2000
match "HTTP/.* 404"

curl -v $base/2000/
match "HTTP/.* 404"

curl -v $base/2018/hello-world
match "HTTP/.* 200"
match -iP "Content-Type: text/html[;\r\n]"

curl -v $base/2018/hello-world/
match "HTTP/.* 302"
match -iP "Location: $redir/2018/hello-world[\r\n]"

curl -v $base/contact
match "HTTP/.* 200"
match -iP "Content-Type: text/html[;\r\n]"

curl -v $base/contact -X POST
match "HTTP/.* 400"

curl -v $base/contact --data name=A --data email=alice@example.com --data company=ACME --data budget=None --data message="Let's get in touch!"
match "HTTP/.* 400" # name length

curl -v $base/contact --data name=Alice --data email=alice --data company=ACME --data budget=None --data message="Let's get in touch!"
match "HTTP/.* 400" # email invalid

curl -v $base/contact --data name=Alice --data email=alice@example.com --data company=ACME --data budget=A --data message="Let's get in touch!"
match "HTTP/.* 400" # budget invalid

# curl -v $base/contact --data name=Alice --data email=alice@example.com --data company= --data budget=Yes --data message="Let's get in touch!!"
# match "HTTP/.* 302" # valid without company

# curl -v $base/contact --data name=Alice --data email=alice@example.com --data company=ACME --data budget=Yes --data message="Let's get in touch!!"
# match "HTTP/.* 302" # valid with company

curl -v $base/contact.html
match "HTTP/.* 302"
match -iP "Location: $redir/contact[\r\n]"

curl -v $base/contact.php
match "HTTP/.* 302"
match -iP "Location: $redir/contact[\r\n]"

curl -v $base/contact/
match "HTTP/.* 302"
match -iP "Location: $redir/contact[\r\n]"

echo "OK ($n)"
Loading