]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: Add tests for variable definition.
authorVarsha Rao <rvarsha016@gmail.com>
Wed, 11 Oct 2017 04:51:11 +0000 (10:21 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 17 Oct 2017 12:01:48 +0000 (14:01 +0200)
This patch adds test cases for a variable definition and redefinition.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/nft-f/0013defines_1 [new file with mode: 0755]
tests/shell/testcases/nft-f/0014defines_1 [new file with mode: 0755]
tests/shell/testcases/nft-f/0015defines_1 [new file with mode: 0755]

diff --git a/tests/shell/testcases/nft-f/0013defines_1 b/tests/shell/testcases/nft-f/0013defines_1
new file mode 100755 (executable)
index 0000000..0537003
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Tests use of variable before definition.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+       echo "Failed to create tmp file" >&2
+       exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var2 = \$var1
+define var1 = lo
+
+table ip t {
+       chain c {
+               iif \$var2
+       }
+}" >> $tmpfile
+
+$NFT -f $tmpfile
diff --git a/tests/shell/testcases/nft-f/0014defines_1 b/tests/shell/testcases/nft-f/0014defines_1
new file mode 100755 (executable)
index 0000000..de5615e
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Tests redefinition of an existing variable.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+       echo "Failed to create tmp file" >&2
+       exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var1 = lo
+define var1 = lo
+
+table ip t {
+       chain c {
+               iif \$var1
+       }
+}" >> $tmpfile
+
+$NFT -f $tmpfile
diff --git a/tests/shell/testcases/nft-f/0015defines_1 b/tests/shell/testcases/nft-f/0015defines_1
new file mode 100755 (executable)
index 0000000..9c1a701
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Tests recursive definition of a variable.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+       echo "Failed to create tmp file" >&2
+       exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var1 = \$var1
+
+table ip t {
+       chain c {
+               iif \$var1
+       }
+}" >> $tmpfile
+
+$NFT -f $tmpfile