selfprivacy-tests/query-services-state.sh

48 lines
1.0 KiB
Bash
Executable File

#! /usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit
: "${DOMAIN:?specify domain name}"
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
readonly QUERY='query AllServices {
services {
allServices {
id
isEnabled
status
}
}
}'
: "${EXPECTED_RESPONSE_FILE:?not set error}"
# shellcheck disable=SC2116
# shellcheck disable=SC2086
REQUEST=$(cat << EOF
{
"query": "$(echo $QUERY)",
"variables": null,
"operationName": "AllServices"
}
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)"
jq <<<"$received_response"
if diff -w -u --color=always "$EXPECTED_RESPONSE_FILE" <(printf "%s\n" "$received_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")
exit 1
fi