test: add smoke test to cover schemas api
This commit is contained in:
parent
ed7a8659d2
commit
48e68b7c77
|
@ -2,42 +2,92 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
[ $# -ne 2 ] && { echo "Usage: $0 ip port"; exit 1; }
|
[ $# -ne 2 ] && { echo "Usage: $0 host port"; exit 1; }
|
||||||
|
|
||||||
IP=$1
|
HOST=$1
|
||||||
PORT=$2
|
PORT=$2
|
||||||
URL="http://$IP:$PORT/status"
|
BASE_URL="http://$HOST:$PORT"
|
||||||
|
|
||||||
## Check if EMQX is responding
|
## Check if EMQX is responding
|
||||||
ATTEMPTS=10
|
wait_for_emqx() {
|
||||||
while ! curl "$URL" >/dev/null 2>&1; do
|
local attempts=10
|
||||||
if [ $ATTEMPTS -eq 0 ]; then
|
local url="$BASE_URL"/status
|
||||||
echo "emqx is not responding on $URL"
|
while ! curl "$url" >/dev/null 2>&1; do
|
||||||
exit 1
|
if [ $attempts -eq 0 ]; then
|
||||||
|
echo "emqx is not responding on $url"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
attempts=$((attempts-1))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
## Get the JSON format status which is jq friendly and includes a version string
|
||||||
|
json_status() {
|
||||||
|
local url="${BASE_URL}/status?format=json"
|
||||||
|
local resp
|
||||||
|
resp="$(curl -s "$url")"
|
||||||
|
if (echo "$resp" | jq . >/dev/null 2>&1); then
|
||||||
|
echo "$resp"
|
||||||
|
else
|
||||||
|
echo 'NOT_JSON'
|
||||||
fi
|
fi
|
||||||
sleep 5
|
}
|
||||||
ATTEMPTS=$((ATTEMPTS-1))
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if the API docs are available
|
## Check if the API docs are available
|
||||||
API_DOCS_URL="http://$IP:$PORT/api-docs/index.html"
|
check_api_docs() {
|
||||||
API_DOCS_STATUS="$(curl -s -o /dev/null -w "%{http_code}" "$API_DOCS_URL")"
|
local url="$BASE_URL/api-docs/index.html"
|
||||||
if [ "$API_DOCS_STATUS" != "200" ]; then
|
local status
|
||||||
echo "emqx is not responding on $API_DOCS_URL"
|
status="$(curl -s -o /dev/null -w "%{http_code}" "$url")"
|
||||||
exit 1
|
if [ "$status" != "200" ]; then
|
||||||
fi
|
echo "emqx is not responding on $API_DOCS_URL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
## Check if the swagger.json contains hidden fields
|
## Check if the swagger.json contains hidden fields
|
||||||
## fail if it does
|
## fail if it does
|
||||||
SWAGGER_JSON_URL="http://$IP:$PORT/api-docs/swagger.json"
|
check_swagger_json() {
|
||||||
## assert swagger.json is valid json
|
local url="$BASE_URL/api-docs/swagger.json"
|
||||||
JSON="$(curl -s "$SWAGGER_JSON_URL")"
|
## assert swagger.json is valid json
|
||||||
echo "$JSON" | jq . >/dev/null
|
JSON="$(curl -s "$url")"
|
||||||
|
echo "$JSON" | jq . >/dev/null
|
||||||
|
|
||||||
if [ "${EMQX_SMOKE_TEST_CHECK_HIDDEN_FIELDS:-yes}" = 'yes' ]; then
|
if [ "${EMQX_SMOKE_TEST_CHECK_HIDDEN_FIELDS:-yes}" = 'yes' ]; then
|
||||||
## assert swagger.json does not contain trie_compaction (which is a hidden field)
|
## assert swagger.json does not contain trie_compaction (which is a hidden field)
|
||||||
if echo "$JSON" | grep -q trie_compaction; then
|
if echo "$JSON" | grep -q trie_compaction; then
|
||||||
echo "swagger.json contains hidden fields"
|
echo "swagger.json contains hidden fields"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_schema_json() {
|
||||||
|
local name="$1"
|
||||||
|
local expected_title="$2"
|
||||||
|
local url="$BASE_URL/api/v5/schemas/$name"
|
||||||
|
local json
|
||||||
|
json="$(curl -s "$url" | jq .)"
|
||||||
|
title="$(echo "$json" | jq -r '.info.title')"
|
||||||
|
if [[ "$title" != "$expected_title" ]]; then
|
||||||
|
echo "unexpected value from GET $url"
|
||||||
|
echo "expected: $expected_title"
|
||||||
|
echo "got : $title"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
wait_for_emqx
|
||||||
|
local JSON_STATUS
|
||||||
|
JSON_STATUS="$(json_status)"
|
||||||
|
check_api_docs
|
||||||
|
check_swagger_json
|
||||||
|
## The json status feature was added after hotconf and bridges schema API
|
||||||
|
if [ "$JSON_STATUS" != 'NOT_JSON' ]; then
|
||||||
|
check_schema_json hotconf "EMQX Hot Conf API Schema"
|
||||||
|
check_schema_json bridges "EMQX Data Bridge API Schema"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|
Loading…
Reference in New Issue