emqx-smoke-test.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. [ $# -ne 2 ] && { echo "Usage: $0 ip port"; exit 1; }
  4. IP=$1
  5. PORT=$2
  6. URL="http://$IP:$PORT/status"
  7. ## Check if EMQX is responding
  8. ATTEMPTS=10
  9. while ! curl "$URL" >/dev/null 2>&1; do
  10. if [ $ATTEMPTS -eq 0 ]; then
  11. echo "emqx is not responding on $URL"
  12. exit 1
  13. fi
  14. sleep 5
  15. ATTEMPTS=$((ATTEMPTS-1))
  16. done
  17. ## Check if the API docs are available
  18. API_DOCS_URL="http://$IP:$PORT/api-docs/index.html"
  19. API_DOCS_STATUS="$(curl -s -o /dev/null -w "%{http_code}" "$API_DOCS_URL")"
  20. if [ "$API_DOCS_STATUS" != "200" ]; then
  21. echo "emqx is not responding on $API_DOCS_URL"
  22. exit 1
  23. fi
  24. ## Check if the swagger.json contains hidden fields
  25. ## fail if it does
  26. SWAGGER_JSON_URL="http://$IP:$PORT/api-docs/swagger.json"
  27. ## assert swagger.json is valid json
  28. JSON="$(curl -s "$SWAGGER_JSON_URL")"
  29. echo "$JSON" | jq . >/dev/null
  30. if [ "${EMQX_SMOKE_TEST_CHECK_HIDDEN_FIELDS:-yes}" = 'yes' ]; then
  31. ## assert swagger.json does not contain trie_compaction (which is a hidden field)
  32. if echo "$JSON" | grep -q trie_compaction; then
  33. echo "swagger.json contains hidden fields"
  34. exit 1
  35. fi
  36. fi