Skip to content

Commit

Permalink
Merge pull request #40 from SimonFrings/integration
Browse files Browse the repository at this point in the history
Clean up and improve structure of integration tests
  • Loading branch information
clue authored Jun 17, 2024
2 parents 21b01f0 + b132d07 commit b80724a
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ served: build
@echo Container running. Use \"docker rm -f {containerId}\" to stop container.

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

deploy:
Expand Down
49 changes: 0 additions & 49 deletions tests/acceptance.sh

This file was deleted.

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

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

n=0
skipping=false
curl() {
skipping=false
out=$($(which curl) "$@" 2>&1);
}
match() {
[[ $skipping == true ]] && return 0
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
}
skipif() {
echo "$out" | grep "$@" >/dev/null && echo -n S && skipping=true || return 0
}

# check index endpoint

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

curl -v $base/invalid
match "HTTP/.* 404"
match -i "Content-Type: text/html"

# check HTTP redirects for `docs` endpoint

curl -v $base/docs
match "HTTP/.* 301"
match -iP "Location: .*/docs/[\r\n]"

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

# check HTTP redirects behind CDN

curl -v $base/docs -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Proto: https'
match "HTTP/.* 301"
skipif -iP "Location: $base/docs/[\r\n]"
match -iP "Location: https://example\.com/docs/[\r\n]"

curl -v $base/docs/ -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Proto: http'
match "HTTP/.* 302"
skipif -iP "Location: $base/docs/getting-started/[\r\n]"
match -iP "Location: http://example\.com/docs/getting-started/[\r\n]"

# check HTTP redirects for chapter endpoints

curl -v $base/docs/getting-started/
match "HTTP/.* 302"
match -iP "Location: .*/docs/getting-started/quickstart/[\r\n]"

curl -v $base/docs/best-practices/
match "HTTP/.* 302"
match -iP "Location: .*/docs/best-practices/controllers/[\r\n]"

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

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

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

# check HTTP redirects for `index.html` at end of path

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

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

curl -v $base/docs/getting-started/quickstart/index.html
match "HTTP/.* 301"
match -iP "Location: .*/docs/getting-started/quickstart/[\r\n]"

# check HTTP redirects for old documentation structure

curl -v $base/docs/more/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./getting-started/philosophy/[\r\n]"

curl -v $base/docs/more/philosophy/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./\.\./getting-started/philosophy/[\r\n]"

curl -v $base/docs/more/architecture/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./\.\./getting-started/philosophy/[\r\n]"

curl -v $base/docs/more/community/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./\.\./getting-started/community/[\r\n]"

curl -v $base/docs/async/child-processes/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./\.\./integrations/child-processes/[\r\n]"

curl -v $base/docs/async/streaming/
match "HTTP/.* 302"
match -iP "Location: .*/\.\./\.\./integrations/streaming/[\r\n]"

# end

echo "OK ($n)"

0 comments on commit b80724a

Please sign in to comment.