From: Thomas Haller <thaller@redhat.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft 1/1] tests: prettify JSON in test output and add helper
Date: Wed, 22 Nov 2023 13:55:57 +0100 [thread overview]
Message-ID: <267d0bff359a01b3222506e272bb1c2b63c154c8.camel@redhat.com> (raw)
In-Reply-To: <ZV31GgRsu6Y7UScC@calendula>
On Wed, 2023-11-22 at 13:33 +0100, Pablo Neira Ayuso wrote:
> Hi,
>
> On Wed, Nov 22, 2023 at 12:19:40PM +0100, Thomas Haller wrote:
> > - 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.
>
> One silly question: Does the prettify hightlights the difference?
Yes. That that is the idea.
>
> tests/py clearly shows what is the difference in the JSON diff that
> quickly helps you identify what is missing.
As always, you will find some result files in /tmp/nft-
test.latest.$USER/, which I usually read with
$ grep --color=always ^ -aR /tmp/nft-test.latest.*/ | less -R
there will be a new file there, named "ruleset-diff.json.pretty".
It contains the content of "./tests/shell/helpers/json-diff-pretty.sh"
output.
For example:
$ cp tests/shell/testcases/bitwise/dumps/0040mark_binop_2.json-nft tests/shell/testcases/bitwise/dumps/0040mark_binop_3.json-nft
$ ./tests/shell/run-tests.sh tests/shell/testcases/bitwise/0040mark_binop_3
leaves a file
/tmp/nft-test.latest.*/test-tests-shell-testcases-bitwise-0040mark_binop_3.1/ruleset-diff.json.pretty
with the following content:
Cmd: "./tests/shell/helpers/json-diff-pretty.sh" "tests/shell/testcases/bitwise/dumps/0040mark_binop_3.json-nft" "/tmp/nft-test.20231122-135045.550.28uKHu/test-tests-shell-testcases-bitwise-0040mark_binop_3.1/ruleset-after.json"
--- tests/shell/testcases/bitwise/dumps/0040mark_binop_3.json-nft 2023-11-22 13:50:12.114098356 +0100
+++ /tmp/nft-test.20231122-135045.550.28uKHu/test-tests-shell-testcases-bitwise-0040mark_binop_3.1/ruleset-after.json 2023-11-22 13:50:45.622065923 +0100
@@ -1 +1 @@
-{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "t", "handle": 0}}, {"chain": {"family": "ip", "table": "t", "name": "c", "handle": 0, "type": "filter", "hook": "output", "prio": 0, "policy": "accept"}}, {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"mangle": {"key": {"ct": {"key": "mark"}}, "value": {"|": [{"<<": [{"payload": {"protocol": "ip", "field": "dscp"}}, 2]}, 16]}}}]}}]}
+{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "t", "handle": 0}}, {"chain": {"family": "ip", "table": "t", "name": "c", "handle": 0, "type": "filter", "hook": "input", "prio": 0, "policy": "accept"}}, {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"mangle": {"key": {"meta": {"key": "mark"}}, "value": {"|": [{"<<": [{"payload": {"protocol": "ip", "field": "dscp"}}, 2]}, 16]}}}]}}]}
--- /dev/fd/63 2023-11-22 13:50:45.627065918 +0100
+++ /dev/fd/62 2023-11-22 13:50:45.627065918 +0100
@@ -21,7 +21,7 @@
"name": "c",
"handle": 0,
"type": "filter",
- "hook": "output",
+ "hook": "input",
"prio": 0,
"policy": "accept"
}
@@ -36,7 +36,7 @@
{
"mangle": {
"key": {
- "ct": {
+ "meta": {
"key": "mark"
}
},
next prev parent reply other threads:[~2023-11-22 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 11:19 [PATCH nft 1/1] tests: prettify JSON in test output and add helper Thomas Haller
2023-11-22 12:33 ` Pablo Neira Ayuso
2023-11-22 12:55 ` Thomas Haller [this message]
2023-11-22 17:36 ` Pablo Neira Ayuso
2023-11-22 18:23 ` Thomas Haller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=267d0bff359a01b3222506e272bb1c2b63c154c8.camel@redhat.com \
--to=thaller@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).