]> git.ipfire.org Git - people/stevee/suricata-verify.git/commitdiff
run: convert cmp tests to python
authorTharushi Jayasekara <tharushi68@gmail.com>
Tue, 16 Feb 2021 18:57:27 +0000 (00:27 +0530)
committerJason Ish <jason.ish@oisf.net>
Tue, 6 Jul 2021 23:02:19 +0000 (17:02 -0600)
run.py
tests/datasets-01/check.sh [deleted file]

diff --git a/run.py b/run.py
index d6da6123cbc30686959ea530ace632bb7af5a2f6..b782e51d43ee18a8b992fff2fc7bbe8fa94feac6 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -40,7 +40,7 @@ import unittest
 import multiprocessing as mp
 from collections import namedtuple
 import threading
-
+import filecmp
 import yaml
 
 WIN32 = sys.platform == "win32"
@@ -306,6 +306,19 @@ def is_version_compatible(version, suri_version, expr):
         return False
     return True
 
+class FileCompareCheck:
+
+    def __init__(self, config, directory):
+        self.config = config
+        self.directory = directory
+
+    def run(self):
+        expected = os.path.join(self.directory, self.config["expected"])
+        filename = self.config["filename"]
+        if filecmp.cmp(expected, filename):
+            return True
+        else:
+            raise TestError("%s %s \nFAILED: verification failed" % (expected, filename))
 
 class ShellCheck:
 
@@ -682,6 +695,11 @@ class TestRunner:
         count = StatsCheck(check, self.output).run()
         return count
 
+    @handle_exceptions
+    def perform_file_compare_checks(self, check, count, test_num, test_name):
+        count = FileCompareCheck(check, self.directory).run()
+        return count
+
     def reset_count(self, dictionary):
         for k in dictionary.keys():
             dictionary[k] = 0
@@ -701,8 +719,8 @@ class TestRunner:
                 self.reset_count(count)
                 for check_count, check in enumerate(self.config["checks"]):
                     for key in check:
-                        if key in ["filter", "shell", "stats"]:
-                            func = getattr(self, "perform_{}_checks".format(key))
+                        if key in ["filter", "shell", "stats", "file-compare"]:
+                            func = getattr(self, "perform_{}_checks".format(key.replace("-","_")))
                             count = func(check=check[key], count=count,
                                     test_num=check_count + 1, test_name=os.path.basename(self.directory))
                         else:
diff --git a/tests/datasets-01/check.sh b/tests/datasets-01/check.sh
deleted file mode 100755 (executable)
index 8bedbf3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-exec cmp datasets.csv ${TEST_DIR}/expected/datasets.csv