diff options
author | Phil Sutter <phil@nwl.cc> | 2023-08-01 13:35:27 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-08-03 14:58:20 +0200 |
commit | f6cc747991758801e4c3eb25bb06840870963cc2 (patch) | |
tree | 2ae998c68d919ad65c72d7d43bc85586671929d6 | |
parent | 28d202216535ac54216f825e511a92d9acea5d3c (diff) |
tests: shell: Review test-cases for destroy command
Having separate files for successful destroy of existing and
non-existing objects is a bit too much, just combine them into one.
While being at it:
* No bashisms, using /bin/sh is fine
* Append '-e' to shebang itself instead of calling 'set'
* Use 'nft -a -e' instead of assuming the created rule's handle value
* Shellcheck warned about curly braces, quote them
Signed-off-by: Phil Sutter <phil@nwl.cc>
-rwxr-xr-x | tests/shell/testcases/chains/0044chain_destroy_0 | 11 | ||||
-rwxr-xr-x | tests/shell/testcases/chains/0045chain_destroy_0 | 8 | ||||
-rw-r--r-- | tests/shell/testcases/chains/dumps/0045chain_destroy_0.nft | 2 | ||||
-rwxr-xr-x | tests/shell/testcases/flowtable/0015destroy_0 | 9 | ||||
-rwxr-xr-x | tests/shell/testcases/flowtable/0016destroy_0 | 6 | ||||
-rw-r--r-- | tests/shell/testcases/flowtable/dumps/0016destroy_0.nft | 2 | ||||
-rwxr-xr-x | tests/shell/testcases/maps/0014destroy_0 | 10 | ||||
-rwxr-xr-x | tests/shell/testcases/maps/0015destroy_0 | 7 | ||||
-rw-r--r-- | tests/shell/testcases/maps/dumps/0015destroy_0.nft | 2 | ||||
-rwxr-xr-x | tests/shell/testcases/rule_management/0012destroy_0 | 9 | ||||
-rwxr-xr-x | tests/shell/testcases/rule_management/0013destroy_0 | 8 | ||||
-rw-r--r-- | tests/shell/testcases/rule_management/dumps/0013destroy_0 | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/sets/0072destroy_0 | 10 | ||||
-rwxr-xr-x | tests/shell/testcases/sets/0073destroy_0 | 7 | ||||
-rw-r--r-- | tests/shell/testcases/sets/dumps/0073destroy_0.nft | 2 |
15 files changed, 32 insertions, 65 deletions
diff --git a/tests/shell/testcases/chains/0044chain_destroy_0 b/tests/shell/testcases/chains/0044chain_destroy_0 index 070021cf..8384da66 100755 --- a/tests/shell/testcases/chains/0044chain_destroy_0 +++ b/tests/shell/testcases/chains/0044chain_destroy_0 @@ -1,7 +1,10 @@ -#!/bin/bash - -set -e +#!/bin/sh -e $NFT add table t -$NFT destroy chain t nochain +# pass for non-existent chain +$NFT destroy chain t c + +# successfully delete existing chain +$NFT add chain t c +$NFT destroy chain t c diff --git a/tests/shell/testcases/chains/0045chain_destroy_0 b/tests/shell/testcases/chains/0045chain_destroy_0 deleted file mode 100755 index b356f8f8..00000000 --- a/tests/shell/testcases/chains/0045chain_destroy_0 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -e - -$NFT add table t -$NFT add chain t c - -$NFT destroy chain t c diff --git a/tests/shell/testcases/chains/dumps/0045chain_destroy_0.nft b/tests/shell/testcases/chains/dumps/0045chain_destroy_0.nft deleted file mode 100644 index 985768ba..00000000 --- a/tests/shell/testcases/chains/dumps/0045chain_destroy_0.nft +++ /dev/null @@ -1,2 +0,0 @@ -table ip t { -} diff --git a/tests/shell/testcases/flowtable/0015destroy_0 b/tests/shell/testcases/flowtable/0015destroy_0 index 4828d818..66fce499 100755 --- a/tests/shell/testcases/flowtable/0015destroy_0 +++ b/tests/shell/testcases/flowtable/0015destroy_0 @@ -1,7 +1,10 @@ -#!/bin/bash +#!/bin/sh -e -set -e $NFT add table t -$NFT add flowtable t f { hook ingress priority 10 \; devices = { lo }\; } +# pass for non-existent flowtable +$NFT destroy flowtable t f + +# successfully delete existing flowtable +$NFT add flowtable t f '{ hook ingress priority 10; devices = { lo }; }' $NFT destroy flowtable t f diff --git a/tests/shell/testcases/flowtable/0016destroy_0 b/tests/shell/testcases/flowtable/0016destroy_0 deleted file mode 100755 index ce23c753..00000000 --- a/tests/shell/testcases/flowtable/0016destroy_0 +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -e -$NFT add table t - -$NFT destroy flowtable t f diff --git a/tests/shell/testcases/flowtable/dumps/0016destroy_0.nft b/tests/shell/testcases/flowtable/dumps/0016destroy_0.nft deleted file mode 100644 index 985768ba..00000000 --- a/tests/shell/testcases/flowtable/dumps/0016destroy_0.nft +++ /dev/null @@ -1,2 +0,0 @@ -table ip t { -} diff --git a/tests/shell/testcases/maps/0014destroy_0 b/tests/shell/testcases/maps/0014destroy_0 index b769276d..14c3f78a 100755 --- a/tests/shell/testcases/maps/0014destroy_0 +++ b/tests/shell/testcases/maps/0014destroy_0 @@ -1,8 +1,10 @@ -#!/bin/bash - -set -e +#!/bin/sh -e $NFT add table x -$NFT add map x y { type ipv4_addr : ipv4_addr\; } +# pass for non-existent map +$NFT destroy map x y + +# successfully delete existing map +$NFT add map x y '{ type ipv4_addr : ipv4_addr; }' $NFT destroy map x y diff --git a/tests/shell/testcases/maps/0015destroy_0 b/tests/shell/testcases/maps/0015destroy_0 deleted file mode 100755 index abad4d57..00000000 --- a/tests/shell/testcases/maps/0015destroy_0 +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -$NFT add table x - -$NFT destroy map x nonmap diff --git a/tests/shell/testcases/maps/dumps/0015destroy_0.nft b/tests/shell/testcases/maps/dumps/0015destroy_0.nft deleted file mode 100644 index 5d4d2caf..00000000 --- a/tests/shell/testcases/maps/dumps/0015destroy_0.nft +++ /dev/null @@ -1,2 +0,0 @@ -table ip x { -} diff --git a/tests/shell/testcases/rule_management/0012destroy_0 b/tests/shell/testcases/rule_management/0012destroy_0 index 1b61155e..85f9c9f6 100755 --- a/tests/shell/testcases/rule_management/0012destroy_0 +++ b/tests/shell/testcases/rule_management/0012destroy_0 @@ -1,7 +1,12 @@ -#!/bin/bash +#!/bin/sh -e -set -e $NFT add table t $NFT add chain t c +# pass for non-existent rule $NFT destroy rule t c handle 3333 + +# successfully delete existing rule +handle=$($NFT -a -e insert rule t c accept | \ + sed -n 's/.*handle \([0-9]*\)$/\1/p') +$NFT destroy rule t c handle "$handle" diff --git a/tests/shell/testcases/rule_management/0013destroy_0 b/tests/shell/testcases/rule_management/0013destroy_0 deleted file mode 100755 index 895c24a4..00000000 --- a/tests/shell/testcases/rule_management/0013destroy_0 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -e -$NFT add table t -$NFT add chain t c -$NFT insert rule t c accept # should have handle 2 - -$NFT destroy rule t c handle 2 diff --git a/tests/shell/testcases/rule_management/dumps/0013destroy_0 b/tests/shell/testcases/rule_management/dumps/0013destroy_0 deleted file mode 100644 index 1e0d1d60..00000000 --- a/tests/shell/testcases/rule_management/dumps/0013destroy_0 +++ /dev/null @@ -1,4 +0,0 @@ -table ip t { - chain c { - } -} diff --git a/tests/shell/testcases/sets/0072destroy_0 b/tests/shell/testcases/sets/0072destroy_0 index c9cf9ff7..fd1d6450 100755 --- a/tests/shell/testcases/sets/0072destroy_0 +++ b/tests/shell/testcases/sets/0072destroy_0 @@ -1,8 +1,10 @@ -#!/bin/bash - -set -e +#!/bin/sh -e $NFT add table x -$NFT add set x s {type ipv4_addr\; size 2\;} +# pass for non-existent set +$NFT destroy set x s + +# successfully delete existing set +$NFT add set x s '{type ipv4_addr; size 2;}' $NFT destroy set x s diff --git a/tests/shell/testcases/sets/0073destroy_0 b/tests/shell/testcases/sets/0073destroy_0 deleted file mode 100755 index a9d65a55..00000000 --- a/tests/shell/testcases/sets/0073destroy_0 +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -$NFT add table x - -$NFT destroy set x s diff --git a/tests/shell/testcases/sets/dumps/0073destroy_0.nft b/tests/shell/testcases/sets/dumps/0073destroy_0.nft deleted file mode 100644 index 5d4d2caf..00000000 --- a/tests/shell/testcases/sets/dumps/0073destroy_0.nft +++ /dev/null @@ -1,2 +0,0 @@ -table ip x { -} |