print curl commands before GraphQL query
parent
c910587498
commit
024a6532cc
|
@ -1,9 +1,10 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o errtrace
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
shopt -s inherit_errexit
|
||||
trap 'echo $LINENO: $BASH_COMMAND; exit 1' ERR
|
||||
|
||||
: "${DOMAIN:?specify domain name}"
|
||||
readonly SERVICE_NAME="${1:?service name not given error}"
|
||||
|
@ -59,10 +60,13 @@ EXPECTED_RESPONSE=$(cat << EOF
|
|||
EOF
|
||||
)
|
||||
|
||||
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||||
--compressed \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")"
|
||||
curl_cmd=(curl --fail-with-body --show-error -s "https://api.$DOMAIN/graphql"
|
||||
--compressed -H 'Content-Type: application/json'
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")
|
||||
|
||||
printf "%s\n" "${curl_cmd[*]}"
|
||||
|
||||
received_response="$("${curl_cmd[@]}")"
|
||||
|
||||
sorted_response="$(jq --sort-keys <<<"$received_response")" \
|
||||
|| { echo "error"; echo "$received_response"; echo -e "QUERY:\n$QUERY"; exit 1; }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o errtrace
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
shopt -s inherit_errexit
|
||||
trap 'echo $LINENO: $BASH_COMMAND; exit 1' ERR
|
||||
|
||||
: "${DOMAIN:?specify domain name}"
|
||||
readonly REBUILD_OP="${1:?nixos-rebuild related API operation not given error, e.g. Rebuild, Rollback, Upgrade}"
|
||||
|
@ -46,10 +47,13 @@ EXPECTED_RESPONSE=$(cat << EOF
|
|||
EOF
|
||||
)
|
||||
|
||||
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||||
--compressed \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")"
|
||||
curl_cmd=(curl --fail-with-body --show-error -s "https://api.$DOMAIN/graphql"
|
||||
--compressed -H 'Content-Type: application/json'
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")
|
||||
|
||||
printf "%s\n" "${curl_cmd[*]}"
|
||||
|
||||
received_response="$("${curl_cmd[@]}")"
|
||||
|
||||
sorted_response="$(jq --sort-keys <<<"$received_response")" \
|
||||
|| { echo "error"; echo "$received_response"; echo -e "QUERY:\n$QUERY"; exit 1; }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o errtrace
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
shopt -s inherit_errexit
|
||||
trap 'echo $LINENO: $BASH_COMMAND; exit 1' ERR
|
||||
|
||||
: "${DOMAIN:?specify domain name}"
|
||||
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
|
||||
|
@ -30,18 +31,24 @@ EOF
|
|||
)
|
||||
readonly REQUEST
|
||||
|
||||
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||||
--compressed \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER" | jq --sort-keys)"
|
||||
curl_cmd=(curl --fail-with-body --show-error -s "https://api.$DOMAIN/graphql"
|
||||
--compressed -H 'Content-Type: application/json'
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")
|
||||
|
||||
jq <<<"$received_response"
|
||||
printf "%s\n" "${curl_cmd[*]}"
|
||||
|
||||
if diff -w -u --color=always "$EXPECTED_RESPONSE_FILE" <(printf "%s\n" "$received_response") 2>/dev/null
|
||||
received_response="$("${curl_cmd[@]}")"
|
||||
|
||||
sorted_response="$(jq --sort-keys <<<"$received_response")" \
|
||||
|| { echo "error"; echo "$received_response"; echo -e "QUERY:\n$QUERY"; exit 1; }
|
||||
|
||||
jq <<<"$sorted_response"
|
||||
|
||||
if diff -w -u --color=always "$EXPECTED_RESPONSE_FILE" <(printf "%s\n" "$sorted_response") 2>/dev/null
|
||||
then
|
||||
echo -e "\e[1;32mOK\e[0m"
|
||||
else
|
||||
echo -e "\e[1;31mFAIL: response does not match!"
|
||||
jd -color "$EXPECTED_RESPONSE_FILE" <(printf "%s" "$received_response")
|
||||
jd -color "$EXPECTED_RESPONSE_FILE" <(printf "%s" "$sorted_response")
|
||||
exit 1
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue