From: Phil Sutter <phil@nwl.cc>
To: Alexandre Knecht <knecht.alexandre@gmail.com>
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de
Subject: Re: [PATCH v5 2/3] tests: shell: add JSON test for all object types
Date: Tue, 20 Jan 2026 15:39:15 +0100 [thread overview]
Message-ID: <aW-Tk8BJd2jrPoIt@orbyte.nwl.cc> (raw)
In-Reply-To: <20260119140813.536515-3-knecht.alexandre@gmail.com>
On Mon, Jan 19, 2026 at 03:08:12PM +0100, Alexandre Knecht wrote:
[...]
> diff --git a/tests/shell/testcases/json/0007add_insert_delete_objects_0 b/tests/shell/testcases/json/0007add_insert_delete_objects_0
> new file mode 100755
> index 00000000..f701b062
> --- /dev/null
> +++ b/tests/shell/testcases/json/0007add_insert_delete_objects_0
> @@ -0,0 +1,145 @@
> +#!/bin/bash
> +
> +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_json)
> +
> +# Comprehensive test for JSON add/insert/delete/replace operations
> +# Tests that all object types work correctly with JSON commands
> +
> +set -e
> +
> +$NFT flush ruleset
> +
> +# ===== ADD operations =====
> +
> +echo "Test 1: Add table"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"table": {"family": "inet", "name": "test"}}}]}
> +EOF
> +
> +echo "Test 2: Add chain"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"chain": {"family": "inet", "table": "test", "name": "input_chain", "type": "filter", "hook": "input", "prio": 0, "policy": "accept"}}}]}
> +EOF
> +
> +echo "Test 3: Add rule"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"rule": {"family": "inet", "table": "test", "chain": "input_chain", "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": 22}}, {"accept": null}]}}}]}
> +EOF
> +
> +echo "Test 4: Add set"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"set": {"family": "inet", "table": "test", "name": "test_set", "type": "ipv4_addr"}}}]}
> +EOF
> +
> +echo "Test 5: Add counter"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"counter": {"family": "inet", "table": "test", "name": "test_counter"}}}]}
> +EOF
> +
> +echo "Test 6: Add quota"
> +$NFT -j -f - << 'EOF'
> +{"nftables": [{"add": {"quota": {"family": "inet", "table": "test", "name": "test_quota", "bytes": 1000000}}}]}
> +EOF
> +
> +# Verify all objects were created
> +$NFT list ruleset > /dev/null || { echo "Failed to list ruleset after add operations"; exit 1; }
The command will succeed even if not a single one of the previous add
commands succeeded. To compare the resulting ruleset against
expectations, use a diff like so:
| EXPECT='table inet test {
| counter test_counter {
| }
| quota test_quota {
| bytes 1000000
| }
| set test_set {
| type ipv4_addr
| }
| chain input_chain {
| type filter hook input priority filter; policy accept;
|
| tcp dport 22 accept
| }
| }'
| $DIFF -u <(echo "$EXPECT") <($NFT list ruleset) || { ... }
Otherwise looks good to me!
Thanks, Phil
next prev parent reply other threads:[~2026-01-20 14:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 14:08 [PATCH v5 0/3] parser_json: support handle for rule positioning Alexandre Knecht
2026-01-19 14:08 ` [PATCH v5 1/3] parser_json: support handle for rule positioning in explicit JSON format Alexandre Knecht
2026-01-20 14:08 ` Phil Sutter
2026-01-20 14:27 ` Alexandre Knecht
2026-01-20 14:56 ` Phil Sutter
2026-01-19 14:08 ` [PATCH v5 2/3] tests: shell: add JSON test for all object types Alexandre Knecht
2026-01-20 14:39 ` Phil Sutter [this message]
2026-01-19 14:08 ` [PATCH v5 3/3] tests: shell: add JSON test for handle-based rule positioning Alexandre Knecht
2026-01-20 14:46 ` Phil Sutter
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=aW-Tk8BJd2jrPoIt@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=knecht.alexandre@gmail.com \
--cc=netfilter-devel@vger.kernel.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