run-node-tests.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # Run every verification case. A case that declares a precondition this machine
  3. # does not meet is counted as skipped and named - it is never counted as passed,
  4. # because a green tally that includes tests which did not run is worse than a
  5. # red one.
  6. set -uo pipefail
  7. cd "$(dirname "$0")/.."
  8. pass=0; fail=0; skip=0
  9. failed=(); skipped=()
  10. for case in tests/nodes/*.json; do
  11. output=$(python3 scripts/verify-node.py "$case" 2>&1)
  12. case_status=$?
  13. name=$(basename "$case" .json)
  14. if [ $case_status -eq 0 ]; then
  15. pass=$((pass + 1))
  16. elif [ $case_status -eq 2 ]; then
  17. skip=$((skip + 1)); skipped+=("$name: ${output#SKIP *: }")
  18. else
  19. fail=$((fail + 1)); failed+=("$name")
  20. printf '\n--- %s\n%s\n' "$name" "$output"
  21. fi
  22. done
  23. # Collections the cases write to as fixtures. A workflow's own storage goes when
  24. # its workflow is deleted, but a shared collection is nobody's to clean up - and
  25. # the database creates one on first write, so every run left another behind in
  26. # the user's list of collections.
  27. cleanup_fixtures() {
  28. local token
  29. token=$(curl -s http://localhost:8090/api/v1/auth/login \
  30. -H 'Content-Type: application/json' \
  31. -d '{"username":"admin","password":"admin"}' 2>/dev/null | jq -r '.accessToken // empty')
  32. [ -z "$token" ] && return 0
  33. for name in $(curl -s http://localhost:8090/api/v1/database/collections \
  34. -H "Authorization: Bearer $token" 2>/dev/null \
  35. | jq -r '.collections[]? | select(startswith("wfprobe_"))'); do
  36. # Dropping asks for the name back as confirmation, deliberately. A
  37. # script has to say it too - the guard is there so nobody drops a
  38. # collection by reflex, and quietly bypassing it here would make this
  39. # script the one place that can.
  40. curl -s -o /dev/null -X DELETE \
  41. "http://localhost:8090/api/v1/database/collections/$name?confirm=$name" \
  42. -H "Authorization: Bearer $token"
  43. done
  44. }
  45. cleanup_fixtures
  46. echo
  47. echo "passed $pass, failed $fail, skipped $skip"
  48. [ ${#skipped[@]} -gt 0 ] && printf 'skipped: %s\n' "${skipped[@]}"
  49. [ ${#failed[@]} -gt 0 ] && printf 'failed: %s\n' "${failed[@]}"
  50. exit $(( fail > 0 ? 1 : 0 ))