-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added two scripts to assert nginx responses in CI
- Loading branch information
1 parent
0a63ec4
commit 48e5679
Showing
3 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# A utility script to assert redirects served up by nginx | ||
# | ||
# Usage: assert-redirects.sh PATH DESTINATION_URL | ||
# | ||
# - PATH - Local URL path, like /docs | ||
# - DESTINATION_URL - Destination URL the direct goes to | ||
|
||
FROM=${1} | ||
TO=${2} | ||
|
||
if [[ -z $FROM || -z $TO ]]; then | ||
echo "Usage: assert-redirects.sh PATH DESTINATION_URL" | ||
exit 1 | ||
fi | ||
|
||
OUTPUT=$(curl --header "X-Forwarded-Proto: https" \ | ||
--silent --output /dev/null \ | ||
--write-out "%{http_code} %{redirect_url}" \ | ||
http://localhost:3001${FROM}) | ||
|
||
CODE=$(echo $OUTPUT | cut -f 1 -d " ") | ||
URL=$(echo $OUTPUT | cut -f 2 -d " ") | ||
|
||
if [ ${CODE} -ne 301 ]; then | ||
echo "Expect a 301 status code, got '${CODE}'" | ||
exit 1 | ||
fi | ||
|
||
if [ ${URL} != ${TO} ]; then | ||
echo "Expected ${FROM} to redirect to ${TO}, got '${URL}' instead" | ||
exit 1 | ||
fi | ||
|
||
echo "OK: '${FROM}' redirects to '${TO}'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# A utility script to assert successful responses served up by nginx | ||
# | ||
# Usage: assert-success.sh PATH | ||
# | ||
# - PATH - Local URL path, like /docs | ||
|
||
URI_PATH=${1} | ||
|
||
if [[ -z $URI_PATH ]]; then | ||
echo "Usage: assert-success.sh PATH" | ||
exit 1 | ||
fi | ||
|
||
CODE=$(curl --header "X-Forwarded-Proto: https" \ | ||
--silent --output /dev/null \ | ||
--write-out "%{http_code}" \ | ||
http://localhost:3001${URI_PATH}) | ||
|
||
if [ ${CODE} -ne 200 ]; then | ||
echo "Expect a 200 status code, got '${CODE}'" | ||
exit 1 | ||
fi | ||
|
||
echo "OK: '${URI_PATH}' returned a 200 status code" |