mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-04 20:06:35 +03:00
tests: run server test shell files through shfmt for consistent indentation
I don't have any particular opinion on what would be a desirable format, it's just a pain working on them as is. This is the first in a series of several smallish changes largely to `test-server.sh`, chipping away at it to make things a bit less convoluted. Ultimately I'm trying to run the python tests against graphql-engine-pro, but to get there I need to get a bit more structure into what we have. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3297 GitOrigin-RevId: 08ecf0604a4d8ace73e9f008bf4abfbf7bdb9393
This commit is contained in:
parent
d097aea394
commit
b892927c45
@ -9,48 +9,47 @@ SERVER_ROOT="$CIRCLECI_FOLDER/../server"
|
||||
|
||||
i=1
|
||||
echoInfo() {
|
||||
echo -e "\033[36m$i. $*\033[0m"
|
||||
i=$[i+1]
|
||||
echo -e "\033[36m$i. $*\033[0m"
|
||||
i=$((i + 1))
|
||||
}
|
||||
|
||||
fail_if_port_busy() {
|
||||
local PORT=$1
|
||||
if nc -z localhost $PORT ; then
|
||||
echo "Port $PORT is busy. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
local PORT=$1
|
||||
if nc -z localhost $PORT; then
|
||||
echo "Port $PORT is busy. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
wait_for_port() {
|
||||
local PORT=$1
|
||||
echo "waiting for $PORT"
|
||||
for _ in $(seq 1 30);
|
||||
do
|
||||
nc -z localhost $PORT && echo "port $PORT is ready" && return
|
||||
echo -n .
|
||||
sleep 0.2
|
||||
done
|
||||
echo "Failed waiting for $PORT" && exit 1
|
||||
local PORT=$1
|
||||
echo "waiting for $PORT"
|
||||
for _ in $(seq 1 30); do
|
||||
nc -z localhost $PORT && echo "port $PORT is ready" && return
|
||||
echo -n .
|
||||
sleep 0.2
|
||||
done
|
||||
echo "Failed waiting for $PORT" && exit 1
|
||||
}
|
||||
|
||||
test_export_metadata_with_access_key() {
|
||||
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Access-Key: $1" > /dev/null
|
||||
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Access-Key: $1" >/dev/null
|
||||
}
|
||||
|
||||
cd $SERVER_ROOT
|
||||
|
||||
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
|
||||
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ]; then
|
||||
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! stack --allow-different-user exec -- which graphql-engine > /dev/null && [ -z "${GRAPHQL_ENGINE:-}" ] ; then
|
||||
if ! stack --allow-different-user exec -- which graphql-engine >/dev/null && [ -z "${GRAPHQL_ENGINE:-}" ]; then
|
||||
echo "Do 'stack build' before tests, or export the location of executable in the GRAPHQL_ENGINE envirnoment variable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GRAPHQL_ENGINE=${GRAPHQL_ENGINE:-"$(stack --allow-different-user exec -- which graphql-engine)"}
|
||||
if ! [ -x "$GRAPHQL_ENGINE" ] ; then
|
||||
if ! [ -x "$GRAPHQL_ENGINE" ]; then
|
||||
echo "$GRAPHQL_ENGINE is not present or is not an executable"
|
||||
exit 1
|
||||
fi
|
||||
@ -58,16 +57,17 @@ fi
|
||||
HGE_PID=""
|
||||
|
||||
run_hge_with_flags() {
|
||||
fail_if_port_busy 8080
|
||||
set -x
|
||||
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* > "$OUTPUT_FOLDER/graphql-engine.log" & HGE_PID=$!
|
||||
set +x
|
||||
wait_for_port 8080
|
||||
fail_if_port_busy 8080
|
||||
set -x
|
||||
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* >"$OUTPUT_FOLDER/graphql-engine.log" &
|
||||
HGE_PID=$!
|
||||
set +x
|
||||
wait_for_port 8080
|
||||
}
|
||||
|
||||
kill_hge() {
|
||||
kill -s INT $HGE_PID || true
|
||||
wait $HGE_PID || true
|
||||
kill -s INT $HGE_PID || true
|
||||
wait $HGE_PID || true
|
||||
}
|
||||
|
||||
trap kill_hge ERR
|
||||
|
@ -9,37 +9,36 @@ SERVER_ROOT="$CIRCLECI_FOLDER/../server"
|
||||
|
||||
i=1
|
||||
echoInfo() {
|
||||
echo -e "\033[36m$i. $*\033[0m"
|
||||
i=$[i+1]
|
||||
echo -e "\033[36m$i. $*\033[0m"
|
||||
i=$((i + 1))
|
||||
}
|
||||
|
||||
fail_if_port_busy() {
|
||||
local PORT=$1
|
||||
if nc -z localhost $PORT ; then
|
||||
echo "Port $PORT is busy. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
local PORT=$1
|
||||
if nc -z localhost $PORT; then
|
||||
echo "Port $PORT is busy. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
wait_for_port() {
|
||||
local PORT=$1
|
||||
echo "waiting for $PORT"
|
||||
for _ in $(seq 1 60);
|
||||
do
|
||||
nc -z localhost $PORT && echo "port $PORT is ready" && return
|
||||
echo -n .
|
||||
sleep 0.2
|
||||
done
|
||||
echo "Failed waiting for $PORT" && exit 1
|
||||
local PORT=$1
|
||||
echo "waiting for $PORT"
|
||||
for _ in $(seq 1 60); do
|
||||
nc -z localhost $PORT && echo "port $PORT is ready" && return
|
||||
echo -n .
|
||||
sleep 0.2
|
||||
done
|
||||
echo "Failed waiting for $PORT" && exit 1
|
||||
}
|
||||
|
||||
test_export_metadata_with_admin_secret() {
|
||||
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Admin-Secret: $1" > /dev/null
|
||||
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Admin-Secret: $1" >/dev/null
|
||||
}
|
||||
|
||||
cd $SERVER_ROOT
|
||||
|
||||
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
|
||||
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ]; then
|
||||
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
|
||||
exit 1
|
||||
fi
|
||||
@ -47,16 +46,17 @@ fi
|
||||
HGE_PID=""
|
||||
|
||||
run_hge_with_flags() {
|
||||
fail_if_port_busy 8080
|
||||
set -x
|
||||
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* > "$OUTPUT_FOLDER/graphql-engine.log" & HGE_PID=$!
|
||||
set +x
|
||||
wait_for_port 8080
|
||||
fail_if_port_busy 8080
|
||||
set -x
|
||||
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* >"$OUTPUT_FOLDER/graphql-engine.log" &
|
||||
HGE_PID=$!
|
||||
set +x
|
||||
wait_for_port 8080
|
||||
}
|
||||
|
||||
kill_hge() {
|
||||
kill -s INT $HGE_PID || true
|
||||
wait $HGE_PID || true
|
||||
kill -s INT $HGE_PID || true
|
||||
wait $HGE_PID || true
|
||||
}
|
||||
|
||||
trap kill_hge ERR
|
||||
@ -65,16 +65,15 @@ trap kill_hge INT
|
||||
OUTPUT_FOLDER=${OUTPUT_FOLDER:-"$CIRCLECI_FOLDER/test-server-flags-output"}
|
||||
mkdir -p "$OUTPUT_FOLDER"
|
||||
|
||||
|
||||
########## Test that we didn't compile with +developer by accident
|
||||
echoInfo "Test we didn't compile in the developer-only APIs"
|
||||
|
||||
run_hge_with_flags
|
||||
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dev/plan_cache)
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dev/plan_cache)
|
||||
if [ "$code" != "404" ]; then
|
||||
echo "Expected a dev endpoint to return 404, but got: $code"
|
||||
exit 1
|
||||
echo "Expected a dev endpoint to return 404, but got: $code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_hge
|
||||
@ -106,17 +105,16 @@ kill_hge
|
||||
|
||||
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
|
||||
|
||||
|
||||
export HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
|
||||
|
||||
fail_if_port_busy 8080
|
||||
timeout 3 stdbuf -o0 "$GRAPHQL_ENGINE" serve > "$OUTPUT_FOLDER/graphql-engine.log" 2>&1 & PID=$!
|
||||
timeout 3 stdbuf -o0 "$GRAPHQL_ENGINE" serve >"$OUTPUT_FOLDER/graphql-engine.log" 2>&1 &
|
||||
PID=$!
|
||||
|
||||
wait $PID || true
|
||||
|
||||
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd"
|
||||
grep -F 'Not a valid boolean text' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
||||
|
||||
grep -F 'Not a valid boolean text' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
||||
|
||||
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false and HASURA_GRAPHQL_ADMIN_SECRET=XXXX
|
||||
key="HGE$RANDOM$RANDOM"
|
||||
@ -131,7 +129,6 @@ echoInfo "Test flag HASURA_GRAPHQL_ADMIN_SECRET=XXXX"
|
||||
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
||||
test_export_metadata_with_admin_secret "$key"
|
||||
|
||||
|
||||
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false"
|
||||
grep -F '"use_prepared_statements":false' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user