[nft,5/9] tests: shell: Add tests for variable definition.

Message ID 97f570632bd36c21237a3997afc61599476a8d63.1507696149.git.rvarsha016@gmail.com
State Accepted
Delegated to: Pablo Neira
Headers show
Series
  • tests: Move tests from files to shell.
Related show

Commit Message

Varsha Rao Oct. 11, 2017, 4:51 a.m.
This patch adds test cases for a variable definition and redefinition.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
 tests/shell/testcases/nft-f/0013defines_1 | 25 +++++++++++++++++++++++++
 tests/shell/testcases/nft-f/0014defines_1 | 25 +++++++++++++++++++++++++
 tests/shell/testcases/nft-f/0015defines_1 | 24 ++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100755 tests/shell/testcases/nft-f/0013defines_1
 create mode 100755 tests/shell/testcases/nft-f/0014defines_1
 create mode 100755 tests/shell/testcases/nft-f/0015defines_1

Patch

diff --git a/tests/shell/testcases/nft-f/0013defines_1 b/tests/shell/testcases/nft-f/0013defines_1
new file mode 100755
index 0000000..5519703
--- /dev/null
+++ b/tests/shell/testcases/nft-f/0013defines_1
@@ -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
index 0000000..914d910
--- /dev/null
+++ b/tests/shell/testcases/nft-f/0014defines_1
@@ -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
index 0000000..1f9db11
--- /dev/null
+++ b/tests/shell/testcases/nft-f/0015defines_1
@@ -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