Fix smoke test JSON parsing

This commit is contained in:
Aaron
2026-01-02 23:58:54 -05:00
parent 13e5788fe1
commit 77bc4c1c36

View File

@@ -84,10 +84,7 @@ extract_json_line() {
json_get() { json_get() {
local key="$1" local key="$1"
if command -v python3 >/dev/null 2>&1; then if command -v python3 >/dev/null 2>&1; then
python3 - "$key" <<'PY' python3 -c 'import json,sys
import json
import sys
key=sys.argv[1] key=sys.argv[1]
try: try:
data=json.load(sys.stdin) data=json.load(sys.stdin)
@@ -99,7 +96,7 @@ if isinstance(val, bool):
print("true" if val else "false") print("true" if val else "false")
else: else:
print(val) print(val)
PY ' "$key"
elif command -v jq >/dev/null 2>&1; then elif command -v jq >/dev/null 2>&1; then
jq -r --arg key "$key" '.[$key] // empty' jq -r --arg key "$key" '.[$key] // empty'
else else
@@ -144,8 +141,7 @@ check_api() {
return return
fi fi
if command -v python3 >/dev/null 2>&1; then if command -v python3 >/dev/null 2>&1; then
if printf "%s" "$body" | python3 - <<'PY' if printf "%s" "$body" | python3 -c 'import json,sys
import json, sys
try: try:
data=json.load(sys.stdin) data=json.load(sys.stdin)
except Exception: except Exception:
@@ -154,7 +150,7 @@ for key in ("services", "hostname", "uptime_seconds"):
if key in data: if key in data:
sys.exit(0) sys.exit(0)
sys.exit(1) sys.exit(1)
PY '
then then
status OK "API responds with JSON" status OK "API responds with JSON"
else else