Skip to content

Commit

Permalink
chore: enhance http-test bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
hpr1999 committed Aug 9, 2024
1 parent 41b83ff commit c6f4b12
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
GODRINK_DB: postgresql://godrink:changeme@localhost:5432/godrink?sslmode=disable
run: "go run . &"
- name: Execute HTTP requests
run: ./http-test/test.sh
run: ./http-test/test.sh -t '**.*.http' -r test-reports -e http-test/http-client.env.json
timeout-minutes: 3
- name: Upload Test results
if: success() || failure() # always run even if the previous step fails
Expand Down
90 changes: 88 additions & 2 deletions http-test/test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
#!/bin/bash


TEST_GLOB="*.http"
OUTPUT="../test-reports"
GODRINK_HOST=localhost
GODRINK_PORT=8080
ENV_FILE="http-client.env.json"
ENV_NAME="dev"

__usage="
This script runs the http-tests against go drink using the intellij http client docker container
To that end, it tries to reach godrink at localhost 8080
Usage: $(basename $0) [OPTIONS]
Options:
-t, --tests <glob> --- A glob listing the .http files to test --- Default: '$TEST_GLOB'
--host <glob> --- The host name at which to find godrink --- Default: '$GODRINK_HOST'
-p, --port <glob> --- The port number under which to find godrink --- Default: '$GODRINK_PORT'
-r, --report <path> --- Output directory for JUnit Test report --- Default: '$OUTPUT'
-e, --env-file <path> --- Path to the intellij http client env file --- Default: '$ENV_FILE'
--env-name <path> --- Name of the intellij http client env --- Default: '$ENV_NAME'
-h, --help --- Print this message
"

while [[ $# -gt 0 ]]; do
case $1 in
-h|"-?"|--help|help)
HELP=1
break
;;
-t|--tests)
TEST_GLOB="$2"
shift # past argument
shift # past value
;;
--host)
GODRINK_HOST="$2"
shift # past argument
shift # past value
;;
-p|--port)
GODRINK_PORT="$2"
shift # past argument
shift # past value
;;
-r|--report)
OUTPUT="$2"
shift # past argument
shift # past value
;;
-e|--env-file)
ENV_FILE="$2"
shift # past argument
shift # past value
;;
--env-name)
ENV_NAME="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
echo "$__usage"
exit 1
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
done

[[ -n "$HELP" ]] && echo "$__usage" && exit 0

if [ ! -f $ENV_FILE ]; then
echo "Environment file not found"
echo "$__usage"
exit 1
fi

set +e
while
(exec 6<>/dev/tcp/localhost/8080) 2>/dev/null
(exec 6<>/dev/tcp/$GODRINK_HOST/$GODRINK_PORT) 2>/dev/null
[ $? == 1 ]
do echo Waiting for Go Drink; sleep 1; done
set -e

docker run --network="host" --rm -v $PWD:/workdir jetbrains/intellij-http-client -e dev -v http-test/http-client.env.json -r test-reports http-test/*.http
docker run --network="host" --rm -v $PWD:/workdir \
jetbrains/intellij-http-client \
--env "$ENV_NAME" \
--env-file "$ENV_FILE" \
--env-variables "godrink_url=$GODRINK_HOST:$GODRINK_PORT" \
--report $OUTPUT \
$TEST_GLOB

0 comments on commit c6f4b12

Please sign in to comment.