]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tests: replace traffic_summary test with python blackbox test
authorGary Lockyer <gary@catalyst.net.nz>
Sun, 6 Aug 2017 22:08:28 +0000 (10:08 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 17 Aug 2017 05:59:38 +0000 (07:59 +0200)
Replace the shell subunit test for script/traffic_summary.pl with a
python black box test.

This involves moving the test files to more standard locations.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Thu Aug 17 07:59:38 CEST 2017 on sn-devel-144

python/samba/tests/blackbox/testdata/traffic_summary.expected [moved from script/testdata/traffic_summary.expected with 100% similarity]
python/samba/tests/blackbox/testdata/traffic_summary.pdml [moved from script/testdata/traffic_summary.pdml with 100% similarity]
python/samba/tests/blackbox/traffic_summary.py [new file with mode: 0644]
script/tests/test_traffic_summary.sh [deleted file]
source4/selftest/tests.py

diff --git a/python/samba/tests/blackbox/traffic_summary.py b/python/samba/tests/blackbox/traffic_summary.py
new file mode 100644 (file)
index 0000000..b2bbc2c
--- /dev/null
@@ -0,0 +1,66 @@
+# Black box tests for script/traffic_leaner
+#
+# Copyright (C) Catalyst IT Ltd. 2017
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Blackbox tests for traffic_summary"""
+
+from contextlib import contextmanager
+import os
+import subprocess
+import tempfile
+
+from samba.tests import BlackboxTestCase
+
+SCRIPT      = "script/traffic_summary.pl"
+DATA_DIR    = "python/samba/tests/blackbox/testdata"
+INPUT       = os.path.join(DATA_DIR, "traffic_summary.pdml")
+EXPECTED_FN = os.path.join(DATA_DIR, "traffic_summary.expected")
+
+
+@contextmanager
+def temp_file(temp_dir):
+    try:
+        tf   = tempfile.NamedTemporaryFile(dir=temp_dir)
+        name = tf.name
+        tf.close()
+        yield name
+    finally:
+        if os.path.exists(name):
+            os.remove(name)
+
+
+class TrafficSummaryTests(BlackboxTestCase):
+
+    def check_twig(self):
+        """Check that perl XML::Twig module is installed.
+        Traffic summary depends on this module being installed.
+        """
+        line = "perl -MXML::Twig -e 1"
+        p = subprocess.Popen(line, shell=True)
+        retcode = p.wait()
+        return (retcode == 0)
+
+    def test_traffic_summary(self):
+        if not self.check_twig():
+            self.skipTest("Perl module XML::Twig is not installed")
+
+        with temp_file(self.tempdir) as output:
+            command  = "%s %s >%s" % (SCRIPT, INPUT, output)
+            print command
+            self.check_run(command)
+            expected = open(EXPECTED_FN).readlines()
+            actual = open(output).readlines()
+            self.assertEquals(expected, actual)
diff --git a/script/tests/test_traffic_summary.sh b/script/tests/test_traffic_summary.sh
deleted file mode 100755 (executable)
index 2dc7bed..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-
-if [ $# -lt 1 ]; then
-cat <<EOF
-Usage: test_traffic_summary.sh
-EOF
-exit 1;
-fi
-
-PREFIX="$1"
-shift 1
-ARGS=$@
-
-. `dirname $0`/../../testprogs/blackbox/subunit.sh
-
-script_dir=`dirname $0`/..
-input="$script_dir/testdata/traffic_summary.pdml"
-expected="$script_dir/testdata/traffic_summary.expected"
-output="$(mktemp $TMPDIR/traffic_summary.XXXXXXXXXXX)"
-ts="$script_dir/traffic_summary.pl"
-
-traffic_summary() {
-
-    $ts $input >$output
-    if [ "$?" != "0" ]; then
-        return 1
-    fi
-
-    diff $output $expected
-    if [ "$?" != "0" ]; then
-        return 1
-    fi
-}
-
-# Check the required perl modules for traffic_summary
-# skip the tests if they are not installed
-perl -MXML::Twig -e 1
-if [ "$?" != "0" ]; then
-    subunit_start_test "traffic_summary"
-    subunit_skip_test "traffic_summary" <<EOF
-perl module XML::Twig not installed
-EOF
-else
-    testit "traffic_summary" traffic_summary
-fi
-
-exit $failed
index c71cc9fb058faf1284b147385bb12175622d92ff..5e54f6fc8bc0fd9884f81da2a53e6d0057042929 100755 (executable)
@@ -700,6 +700,9 @@ planoldpythontestsuite("ad_dc_ntvfs",
 planoldpythontestsuite("ad_dc_ntvfs",
                        "samba.tests.blackbox.traffic_learner",
                        extra_args=['-U"$USERNAME%$PASSWORD"'])
+planoldpythontestsuite("ad_dc_ntvfs",
+                       "samba.tests.blackbox.traffic_summary",
+                       extra_args=['-U"$USERNAME%$PASSWORD"'])
 
 plantestsuite_loadlist("samba4.ldap.python(ad_dc_ntvfs)", "ad_dc_ntvfs", [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '$LOADLIST', '$LISTOPT'])
 plantestsuite_loadlist("samba4.tokengroups.krb5.python(ad_dc_ntvfs)", "ad_dc_ntvfs:local", [python, os.path.join(samba4srcdir, "dsdb/tests/python/token_group.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '-k', 'yes', '$LOADLIST', '$LISTOPT'])