#!/usr/bin/env bash # Run every verification case. A case that declares a precondition this machine # does not meet is counted as skipped and named - it is never counted as passed, # because a green tally that includes tests which did not run is worse than a # red one. set -uo pipefail cd "$(dirname "$0")/.." pass=0; fail=0; skip=0 failed=(); skipped=() for case in tests/nodes/*.json; do output=$(python3 scripts/verify-node.py "$case" 2>&1) case_status=$? name=$(basename "$case" .json) if [ $case_status -eq 0 ]; then pass=$((pass + 1)) elif [ $case_status -eq 2 ]; then skip=$((skip + 1)); skipped+=("$name: ${output#SKIP *: }") else fail=$((fail + 1)); failed+=("$name") printf '\n--- %s\n%s\n' "$name" "$output" fi done # Collections the cases write to as fixtures. A workflow's own storage goes when # its workflow is deleted, but a shared collection is nobody's to clean up - and # the database creates one on first write, so every run left another behind in # the user's list of collections. cleanup_fixtures() { local token token=$(curl -s http://localhost:8090/api/v1/auth/login \ -H 'Content-Type: application/json' \ -d '{"username":"admin","password":"admin"}' 2>/dev/null | jq -r '.accessToken // empty') [ -z "$token" ] && return 0 for name in $(curl -s http://localhost:8090/api/v1/database/collections \ -H "Authorization: Bearer $token" 2>/dev/null \ | jq -r '.collections[]? | select(startswith("wfprobe_"))'); do # Dropping asks for the name back as confirmation, deliberately. A # script has to say it too - the guard is there so nobody drops a # collection by reflex, and quietly bypassing it here would make this # script the one place that can. curl -s -o /dev/null -X DELETE \ "http://localhost:8090/api/v1/database/collections/$name?confirm=$name" \ -H "Authorization: Bearer $token" done } cleanup_fixtures echo echo "passed $pass, failed $fail, skipped $skip" [ ${#skipped[@]} -gt 0 ] && printf 'skipped: %s\n' "${skipped[@]}" [ ${#failed[@]} -gt 0 ] && printf 'failed: %s\n' "${failed[@]}" exit $(( fail > 0 ? 1 : 0 ))