From: Michał Kępień Date: Sat, 25 Oct 2025 05:37:48 +0000 (+0200) Subject: Use jq in system tests inspecting JSON data X-Git-Tag: v9.21.15~36^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b494e02761e9996a6619ed31a17ff0b6f32647eb;p=thirdparty%2Fbind9.git 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. --- diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh index 314eb0ab199..c535e85de21 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