Skip to content

Commit bcdeca8

Browse files
committed
Add header and common header support
1 parent ac9ed6c commit bcdeca8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

auto_test.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ run() {
3232
URL=$(jq -r '.url' $FILE)
3333
ACCESS_TOKEN=$(jq -r '.accessToken' $FILE)
3434
ID_TOKEN=$(jq -r '.idToken' $FILE)
35-
35+
COMMON_HEADER=$(cat $FILE | jq -r -c ". | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
3636
case $1 in
3737
all)
3838
api_factory "$(jq -r '.testCases | keys[]' $FILE)"
@@ -51,6 +51,7 @@ api_factory() {
5151
ROUTE=$(jq -r ".testCases.$TEST_CASE.path" $FILE)
5252
BODY="$(jq -r ".testCases.$TEST_CASE.body" $FILE)"
5353
QUERY_PARAMS=$(cat $FILE | jq -r ".testCases.$TEST_CASE | select(.query != null) | .query | to_entries | map(\"\(.key)=\(.value|tostring)\") | join(\"&\") | \"?\" + . ")
54+
REQUEST_HEADER=$(cat $FILE | jq -r ".testCases.$TEST_CASE | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
5455
METHOD="$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE)"
5556
call_api
5657
echo ""
@@ -59,10 +60,17 @@ api_factory() {
5960
}
6061

6162
call_api() {
62-
echo "$METHOD $URL$ROUTE$QUERY_PARAMS"
63-
local raw_output=$(curl -is --request $METHOD $URL$ROUTE$QUERY_PARAMS \
64-
--header "Authorization: Bearer $ACCESS_TOKEN : $ID_TOKEN" \
65-
--data "$BODY" -w '\n{ "ResponseTime": "%{time_total}s" }' || echo "AUTO_API_ERROR")
63+
# curl -ivs --request $METHOD "$URL$ROUTE$QUERY_PARAMS" \
64+
# --data "$BODY" \
65+
# "$COMMON_HEADER" \
66+
# "$REQUEST_HEADER" \
67+
# -w '\n{ "ResponseTime": "%{time_total}s" }\n'
68+
local raw_output=$(curl -is --request $METHOD "$URL$ROUTE$QUERY_PARAMS" \
69+
--data "$BODY" \
70+
"$COMMON_HEADER" \
71+
"$REQUEST_HEADER" \
72+
-w '\n{ "ResponseTime": "%{time_total}s" }' || echo "AUTO_API_ERROR")
73+
6674
if [[ $raw_output == *"AUTO_API_ERROR"* ]]; then
6775
echo "Problem connecting to $URL"
6876
return 1

0 commit comments

Comments
 (0)