From 3fd757de5f090493979480be2fc0e802d30ffd39 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 10 Jun 2024 17:13:13 +0200 Subject: [PATCH 1/3] Rename integration tests to `integration.bash` --- Makefile | 2 +- tests/{acceptance.sh => integration.bash} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{acceptance.sh => integration.bash} (100%) diff --git a/Makefile b/Makefile index 3ce4e16..301085b 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/tests/acceptance.sh b/tests/integration.bash similarity index 100% rename from tests/acceptance.sh rename to tests/integration.bash From b3b1e8b67a917db5bd0783eb597205110ea8f8c8 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 10 Jun 2024 18:42:50 +0200 Subject: [PATCH 2/3] Clean up and improve structure of integration tests --- tests/integration.bash | 114 ++++++++++++++++++++++++++++++++--------- 1 file changed, 91 insertions(+), 23 deletions(-) diff --git a/tests/integration.bash b/tests/integration.bash index 96c7f41..ffbb382 100755 --- a/tests/integration.bash +++ b/tests/integration.bash @@ -3,47 +3,115 @@ base=${1:-http://localhost:8080} 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 && return 1 || return 0 + echo "$out" | grep "$@" >/dev/null && echo -n S && skipping=true || return 0 } -out=$(curl -v $base/ 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/html[\r\n]" -out=$(curl -v $base/invalid 2>&1); match "HTTP/.* 404" && match -i "Content-Type: text/html" +# 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" -out=$(curl -v $base/docs 2>&1); match "HTTP/.* 301" && match -iP "Location: .*/docs/[\r\n]" -out=$(curl -v $base/docs/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/getting-started/[\r\n]" +# check HTTP redirects for `docs` endpoint -out=$(curl -v $base/docs -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Proto: https' 2>&1); +curl -v $base/docs match "HTTP/.* 301" -skipif -iP "Location: $base/docs/[\r\n]" && +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]" -out=$(curl -v $base/docs/ -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Proto: http' 2>&1); +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]" && +skipif -iP "Location: $base/docs/getting-started/[\r\n]" match -iP "Location: http://example\.com/docs/getting-started/[\r\n]" -out=$(curl -v $base/docs/getting-started/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/getting-started/quickstart/[\r\n]" -out=$(curl -v $base/docs/best-practices/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/best-practices/controllers/[\r\n]" -out=$(curl -v $base/docs/api/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/api/app/[\r\n]" -out=$(curl -v $base/docs/async/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/async/fibers/[\r\n]" -out=$(curl -v $base/docs/integrations/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/docs/integrations/database/[\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]" -out=$(curl -v $base/index.html 2>&1); match "HTTP/.* 301" && match -iP "Location: .*/[\r\n]" -out=$(curl -v $base/docs/index.html 2>&1); match "HTTP/.* 301" && match -iP "Location: .*/docs/[\r\n]" -out=$(curl -v $base/docs/getting-started/quickstart/index.html 2>&1); match "HTTP/.* 301" && match -iP "Location: .*/docs/getting-started/quickstart/[\r\n]" +curl -v $base/docs/more/philosophy/ +match "HTTP/.* 302" +match -iP "Location: .*/\.\./\.\./getting-started/philosophy/[\r\n]" -out=$(curl -v $base/docs/more/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./getting-started/philosophy/[\r\n]" -out=$(curl -v $base/docs/more/philosophy/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./\.\./getting-started/philosophy/[\r\n]" -out=$(curl -v $base/docs/more/architecture/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./\.\./getting-started/philosophy/[\r\n]" -out=$(curl -v $base/docs/more/community/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./\.\./getting-started/community/[\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]" -out=$(curl -v $base/docs/async/child-processes/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./\.\./integrations/child-processes/[\r\n]" -out=$(curl -v $base/docs/async/streaming/ 2>&1); match "HTTP/.* 302" && match -iP "Location: .*/\.\./\.\./integrations/streaming/[\r\n]" +# end echo "OK ($n)" From b132d07afc3ff07f81a5b4dffb85e66ab909a257 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 10 Jun 2024 18:45:49 +0200 Subject: [PATCH 3/3] Ignore trailing slash for integration tests --- tests/integration.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration.bash b/tests/integration.bash index ffbb382..b926f31 100755 --- a/tests/integration.bash +++ b/tests/integration.bash @@ -1,6 +1,7 @@ #!/bin/bash -base=${1:-http://localhost:8080} +base=${1:-http://localhost:8080/} +base=${base%/} n=0 skipping=false