Fix smoke test JSON parsing
This commit is contained in:
@@ -84,22 +84,19 @@ 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
|
key=sys.argv[1]
|
||||||
import sys
|
|
||||||
|
|
||||||
key = sys.argv[1]
|
|
||||||
try:
|
try:
|
||||||
data = json.load(sys.stdin)
|
data=json.load(sys.stdin)
|
||||||
except Exception:
|
except Exception:
|
||||||
print("")
|
print("")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
val = data.get(key, "")
|
val=data.get(key, "")
|
||||||
if isinstance(val, bool):
|
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,17 +141,16 @@ 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:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
for key in ("services", "hostname", "uptime_seconds"):
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user