summaryrefslogtreecommitdiffstats
path: root/tests/shell/helpers/json-diff-pretty.sh
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-11-22 12:19:40 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2023-11-22 18:51:06 +0100
commitca3190fffd50e17289ed280a5326a53467491662 (patch)
treef7ed3ab0bb0d08000f59a48ea7a81d6731175de5 /tests/shell/helpers/json-diff-pretty.sh
parent485efcd3df69999d713031433d862147eba15cde (diff)
tests/shell: prettify JSON in test output and add helper
- add helper script "json-pretty.sh" for prettify/format JSON. It uses either `jq` or a `python` fallback. In my tests, they produce the same output, but the output is not guaranteed to be stable. This is mainly for informational purpose. - add a "json-diff-pretty.sh" which prettifies two JSON inputs and shows a diff of them. - in "test-wrapper.sh", after the check for a .json-nft dump fails, also call "json-diff-pretty.sh" and write the output to "ruleset-diff.json.pretty". This is beside "ruleset-diff.json", which contains the original diff. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/shell/helpers/json-diff-pretty.sh')
-rwxr-xr-xtests/shell/helpers/json-diff-pretty.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/shell/helpers/json-diff-pretty.sh b/tests/shell/helpers/json-diff-pretty.sh
new file mode 100755
index 00000000..bebb7e8e
--- /dev/null
+++ b/tests/shell/helpers/json-diff-pretty.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -e
+
+BASEDIR="$(dirname "$0")"
+
+[ $# -eq 2 ] || (echo "$0: expects two JSON files as arguments" ; exit 1)
+
+FILE1="$1"
+FILE2="$2"
+
+pretty()
+{
+ "$BASEDIR/json-pretty.sh" < "$1" 2>&1 || :
+}
+
+echo "Cmd: \"$0\" \"$FILE1\" \"$FILE2\""
+diff -u "$FILE1" "$FILE2" 2>&1 || :
+diff -u <(pretty "$FILE1") <(pretty "$FILE2") 2>&1 || :