]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests: xlate-test: support multiline expectation
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 3 Jun 2021 22:19:40 +0000 (00:19 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 7 Jun 2021 19:35:27 +0000 (21:35 +0200)
Extend translation test to deal with multiline translation, e.g.

iptables-translate -A INPUT -m connlimit --connlimit-above 2
nft add set ip filter connlimit0 { type ipv4_addr; flags dynamic; }
nft add rule ip filter INPUT add @connlimit0 { ip saddr ct count over 2 } counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
xlate-test.py

index 4c014f9bd269a6a6052cd81da51790212ff8e3da..cba98b6e8e4910697e776310d0b15d6ca990a255 100755 (executable)
@@ -39,14 +39,21 @@ def run_test(name, payload):
     tests = passed = failed = errors = 0
     result = []
 
-    for line in payload:
+    line = payload.readline()
+    while line:
         if line.startswith(keywords):
             tests += 1
             process = Popen([ xtables_nft_multi ] + shlex.split(line), stdout=PIPE, stderr=PIPE)
             (output, error) = process.communicate()
             if process.returncode == 0:
                 translation = output.decode("utf-8").rstrip(" \n")
-                expected = next(payload).rstrip(" \n")
+                expected = payload.readline().rstrip(" \n")
+                next_expected = payload.readline().rstrip(" \n")
+                if next_expected.startswith("nft"):
+                    expected += "\n" + next_expected
+                    line = payload.readline()
+                else:
+                    line = next_expected
                 if translation != expected:
                     test_passed = False
                     failed += 1
@@ -62,6 +69,9 @@ def run_test(name, payload):
                 errors += 1
                 result.append(name + ": " + red("Error: ") + "iptables-translate failure")
                 result.append(error.decode("utf-8"))
+                line = payload.readline()
+        else:
+                line = payload.readline()
     if (passed == tests) and not args.test:
         print(name + ": " + green("OK"))
     if not test_passed: