Fix smoke test JSON parsing
This commit is contained in:
@@ -84,22 +84,19 @@ extract_json_line() {
|
||||
json_get() {
|
||||
local key="$1"
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
python3 - "$key" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
key = sys.argv[1]
|
||||
python3 -c 'import json,sys
|
||||
key=sys.argv[1]
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
data=json.load(sys.stdin)
|
||||
except Exception:
|
||||
print("")
|
||||
sys.exit(1)
|
||||
val = data.get(key, "")
|
||||
val=data.get(key, "")
|
||||
if isinstance(val, bool):
|
||||
print("true" if val else "false")
|
||||
else:
|
||||
print(val)
|
||||
PY
|
||||
' "$key"
|
||||
elif command -v jq >/dev/null 2>&1; then
|
||||
jq -r --arg key "$key" '.[$key] // empty'
|
||||
else
|
||||
@@ -144,17 +141,16 @@ check_api() {
|
||||
return
|
||||
fi
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
if printf "%s" "$body" | python3 - <<'PY'
|
||||
import json, sys
|
||||
if printf "%s" "$body" | python3 -c 'import json,sys
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
data=json.load(sys.stdin)
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
for key in ("services", "hostname", "uptime_seconds"):
|
||||
for key in ("services","hostname","uptime_seconds"):
|
||||
if key in data:
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
PY
|
||||
'
|
||||
then
|
||||
status OK "API responds with JSON"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user