mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-01 12:31:59 +00:00
- resolvespec/restheadspec: single and batch delete use one transaction - add sqlmock tests for delete transaction behaviour - testmodels: serial integer ids; update tests accordingly - add compose testserver, smoke script, podman-first Makefile targets
36 lines
1.4 KiB
Bash
Executable File
36 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Delete-path smoke test against the compose test server.
|
|
# Usage: scripts/testserver-smoke.sh [base_url] (COMPOSE overrides the compose command)
|
|
set -euo pipefail
|
|
|
|
BASE="${1:-http://localhost:8080}"
|
|
if [ -z "${COMPOSE:-}" ]; then
|
|
if command -v podman >/dev/null 2>&1; then COMPOSE="podman compose"; else COMPOSE="docker compose"; fi
|
|
fi
|
|
TS="$(date +%s)"
|
|
BODY="$(mktemp)"
|
|
trap 'rm -f "$BODY"' EXIT
|
|
|
|
# call <json> [path-suffix] -> prints HTTP status, body in $BODY
|
|
call() {
|
|
curl -s -o "$BODY" -w '%{http_code}' -X POST "$BASE/public/departments${2:-}" \
|
|
-H 'Content-Type: application/json' -d "$1"
|
|
}
|
|
expect() { # name want got
|
|
if [ "$2" != "$3" ]; then echo "FAIL $1: want $2 got $3: $(cat "$BODY")"; exit 1; fi
|
|
echo "ok $1 ($3)"
|
|
}
|
|
ids() { grep -o '"id":[0-9]*' "$BODY" | cut -d: -f2; }
|
|
|
|
expect create 200 "$(call "{\"operation\":\"create\",\"data\":{\"name\":\"Smoke\",\"code\":\"S$TS\"}}")"
|
|
ID="$(ids | head -1)"
|
|
expect delete 200 "$(call '{"operation":"delete"}' "/$ID")"
|
|
expect delete-again 404 "$(call '{"operation":"delete"}' "/$ID")"
|
|
|
|
expect batch-create 200 "$(call "{\"operation\":\"create\",\"data\":[{\"name\":\"B\",\"code\":\"B1$TS\"},{\"name\":\"B\",\"code\":\"B2$TS\"}]}")"
|
|
B1="$(ids | sed -n 1p)"; B2="$(ids | sed -n 2p)"
|
|
expect batch-delete 200 "$(call "{\"operation\":\"delete\",\"data\":[\"$B1\",\"$B2\"]}")"
|
|
|
|
echo "--- dbtrace"
|
|
$COMPOSE logs testserver 2>&1 | grep 'dbtrace' | tail -20 || true
|