Skip to content

Commit b892927

Browse files
robxhasura-bot
authored andcommitted
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: hasura/graphql-engine-mono#3297 GitOrigin-RevId: 08ecf0604a4d8ace73e9f008bf4abfbf7bdb9393
1 parent d097aea commit b892927

3 files changed

Lines changed: 831 additions & 824 deletions

File tree

‎.circleci/test-deprecated-server-flags.sh‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,65 @@ SERVER_ROOT="$CIRCLECI_FOLDER/../server"
99

1010
i=1
1111
echoInfo() {
12-
echo -e "\033[36m$i. $*\033[0m"
13-
i=$[i+1]
12+
echo -e "\033[36m$i. $*\033[0m"
13+
i=$((i + 1))
1414
}
1515

1616
fail_if_port_busy() {
17-
local PORT=$1
18-
if nc -z localhost $PORT ; then
19-
echo "Port $PORT is busy. Exiting"
20-
exit 1
21-
fi
17+
local PORT=$1
18+
if nc -z localhost $PORT; then
19+
echo "Port $PORT is busy. Exiting"
20+
exit 1
21+
fi
2222
}
2323

2424
wait_for_port() {
25-
local PORT=$1
26-
echo "waiting for $PORT"
27-
for _ in $(seq 1 30);
28-
do
29-
nc -z localhost $PORT && echo "port $PORT is ready" && return
30-
echo -n .
31-
sleep 0.2
32-
done
33-
echo "Failed waiting for $PORT" && exit 1
25+
local PORT=$1
26+
echo "waiting for $PORT"
27+
for _ in $(seq 1 30); do
28+
nc -z localhost $PORT && echo "port $PORT is ready" && return
29+
echo -n .
30+
sleep 0.2
31+
done
32+
echo "Failed waiting for $PORT" && exit 1
3433
}
3534

3635
test_export_metadata_with_access_key() {
37-
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Access-Key: $1" > /dev/null
36+
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Access-Key: $1" >/dev/null
3837
}
3938

4039
cd $SERVER_ROOT
4140

42-
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
41+
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ]; then
4342
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
4443
exit 1
4544
fi
4645

47-
if ! stack --allow-different-user exec -- which graphql-engine > /dev/null && [ -z "${GRAPHQL_ENGINE:-}" ] ; then
46+
if ! stack --allow-different-user exec -- which graphql-engine >/dev/null && [ -z "${GRAPHQL_ENGINE:-}" ]; then
4847
echo "Do 'stack build' before tests, or export the location of executable in the GRAPHQL_ENGINE envirnoment variable"
4948
exit 1
5049
fi
5150

5251
GRAPHQL_ENGINE=${GRAPHQL_ENGINE:-"$(stack --allow-different-user exec -- which graphql-engine)"}
53-
if ! [ -x "$GRAPHQL_ENGINE" ] ; then
52+
if ! [ -x "$GRAPHQL_ENGINE" ]; then
5453
echo "$GRAPHQL_ENGINE is not present or is not an executable"
5554
exit 1
5655
fi
5756

5857
HGE_PID=""
5958

6059
run_hge_with_flags() {
61-
fail_if_port_busy 8080
62-
set -x
63-
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* > "$OUTPUT_FOLDER/graphql-engine.log" & HGE_PID=$!
64-
set +x
65-
wait_for_port 8080
60+
fail_if_port_busy 8080
61+
set -x
62+
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* >"$OUTPUT_FOLDER/graphql-engine.log" &
63+
HGE_PID=$!
64+
set +x
65+
wait_for_port 8080
6666
}
6767

6868
kill_hge() {
69-
kill -s INT $HGE_PID || true
70-
wait $HGE_PID || true
69+
kill -s INT $HGE_PID || true
70+
wait $HGE_PID || true
7171
}
7272

7373
trap kill_hge ERR

‎.circleci/test-server-flags.sh‎

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,54 @@ SERVER_ROOT="$CIRCLECI_FOLDER/../server"
99

1010
i=1
1111
echoInfo() {
12-
echo -e "\033[36m$i. $*\033[0m"
13-
i=$[i+1]
12+
echo -e "\033[36m$i. $*\033[0m"
13+
i=$((i + 1))
1414
}
1515

1616
fail_if_port_busy() {
17-
local PORT=$1
18-
if nc -z localhost $PORT ; then
19-
echo "Port $PORT is busy. Exiting"
20-
exit 1
21-
fi
17+
local PORT=$1
18+
if nc -z localhost $PORT; then
19+
echo "Port $PORT is busy. Exiting"
20+
exit 1
21+
fi
2222
}
2323

2424
wait_for_port() {
25-
local PORT=$1
26-
echo "waiting for $PORT"
27-
for _ in $(seq 1 60);
28-
do
29-
nc -z localhost $PORT && echo "port $PORT is ready" && return
30-
echo -n .
31-
sleep 0.2
32-
done
33-
echo "Failed waiting for $PORT" && exit 1
25+
local PORT=$1
26+
echo "waiting for $PORT"
27+
for _ in $(seq 1 60); do
28+
nc -z localhost $PORT && echo "port $PORT is ready" && return
29+
echo -n .
30+
sleep 0.2
31+
done
32+
echo "Failed waiting for $PORT" && exit 1
3433
}
3534

3635
test_export_metadata_with_admin_secret() {
37-
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Admin-Secret: $1" > /dev/null
36+
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Admin-Secret: $1" >/dev/null
3837
}
3938

4039
cd $SERVER_ROOT
4140

42-
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
41+
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ]; then
4342
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
4443
exit 1
4544
fi
4645

4746
HGE_PID=""
4847

4948
run_hge_with_flags() {
50-
fail_if_port_busy 8080
51-
set -x
52-
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* > "$OUTPUT_FOLDER/graphql-engine.log" & HGE_PID=$!
53-
set +x
54-
wait_for_port 8080
49+
fail_if_port_busy 8080
50+
set -x
51+
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* >"$OUTPUT_FOLDER/graphql-engine.log" &
52+
HGE_PID=$!
53+
set +x
54+
wait_for_port 8080
5555
}
5656

5757
kill_hge() {
58-
kill -s INT $HGE_PID || true
59-
wait $HGE_PID || true
58+
kill -s INT $HGE_PID || true
59+
wait $HGE_PID || true
6060
}
6161

6262
trap kill_hge ERR
@@ -65,16 +65,15 @@ trap kill_hge INT
6565
OUTPUT_FOLDER=${OUTPUT_FOLDER:-"$CIRCLECI_FOLDER/test-server-flags-output"}
6666
mkdir -p "$OUTPUT_FOLDER"
6767

68-
6968
########## Test that we didn't compile with +developer by accident
7069
echoInfo "Test we didn't compile in the developer-only APIs"
7170

7271
run_hge_with_flags
7372

74-
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dev/plan_cache)
73+
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dev/plan_cache)
7574
if [ "$code" != "404" ]; then
76-
echo "Expected a dev endpoint to return 404, but got: $code"
77-
exit 1
75+
echo "Expected a dev endpoint to return 404, but got: $code"
76+
exit 1
7877
fi
7978

8079
kill_hge
@@ -106,17 +105,16 @@ kill_hge
106105

107106
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
108107

109-
110108
export HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
111109

112110
fail_if_port_busy 8080
113-
timeout 3 stdbuf -o0 "$GRAPHQL_ENGINE" serve > "$OUTPUT_FOLDER/graphql-engine.log" 2>&1 & PID=$!
111+
timeout 3 stdbuf -o0 "$GRAPHQL_ENGINE" serve >"$OUTPUT_FOLDER/graphql-engine.log" 2>&1 &
112+
PID=$!
114113

115114
wait $PID || true
116115

117116
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd"
118-
grep -F 'Not a valid boolean text' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
119-
117+
grep -F 'Not a valid boolean text' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
120118

121119
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false and HASURA_GRAPHQL_ADMIN_SECRET=XXXX
122120
key="HGE$RANDOM$RANDOM"
@@ -131,7 +129,6 @@ echoInfo "Test flag HASURA_GRAPHQL_ADMIN_SECRET=XXXX"
131129
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
132130
test_export_metadata_with_admin_secret "$key"
133131

134-
135132
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false"
136133
grep -F '"use_prepared_statements":false' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
137134

0 commit comments

Comments
 (0)