From 1f0ed3c47909db6560d790d7f06285261abc49ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Sat, 25 Oct 2025 07:37:48 +0200 Subject: [PATCH] Use jq in system tests inspecting JSON data Inspecting JSON data using grep is error-prone, overly lax in some ways, overly strict in others, and neither accurate nor expressive. Use jq for inspecting JSON data in the "statschannel" and "synthfromdnssec" system tests to address these deficiencies. (cherry picked from commit b494e02761e9996a6619ed31a17ff0b6f32647eb) --- bin/tests/system/statschannel/tests.sh | 10 +++++----- bin/tests/system/synthfromdnssec/tests.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh index 314eb0ab19..c535e85de2 100644 --- a/bin/tests/system/statschannel/tests.sh +++ b/bin/tests/system/statschannel/tests.sh @@ -734,19 +734,19 @@ _wait_for_transfers() { if [ $count != 1 ]; then return 1; fi fi - if [ "$PERL_JSON" ]; then + if [ "$PERL_JSON" ] && [ -x "$JQ" ]; then getxfrins json j$n || return 1 # We expect 4 transfers - count=$(grep -c -E '"state":"(Zone Transfer Request|First Data|Receiving AXFR Data)"' xfrins.json.j$n) + count=$("$JQ" '.views._default.xfrins | length' /dev/null || ret=1 + test $("${JQ}" ".nsstats.${synthesized}" <$json) -eq $count || ret=1 else - grep '"'$synthesized'":' $json >/dev/null && ret=1 + "${JQ}" -e '.nsstats | has("'"${synthesized}"'")' <$json >/dev/null && ret=1 fi n=$((n + 1)) if [ $ret != 0 ]; then echo_i "failed"; fi