aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-14 19:32:10 +0100
committerPeter Wu <peter@lekensteyn.nl>2018-11-15 22:56:47 +0000
commitd38ab1bde0f1183ecfdec2a4aa8d2d202c2302a9 (patch)
tree77b76733b60c20432c0b1f392e28302988a2b15d /test
parentbd84c71668294f4fd382ec5265f0001839f08e85 (diff)
test: convert suite_nameres to use fixtures
Create a special custom profile just for the nameres tests, instead of doing this for all tests. Other tests do not need it. Change-Id: I41de0ece9dcf1ee310957beab2bbee0a99784753 Reviewed-on: https://code.wireshark.org/review/30633 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures_ws.py1
-rw-r--r--test/suite_nameres.py95
2 files changed, 57 insertions, 39 deletions
diff --git a/test/fixtures_ws.py b/test/fixtures_ws.py
index 67745acb95..9917910091 100644
--- a/test/fixtures_ws.py
+++ b/test/fixtures_ws.py
@@ -184,4 +184,3 @@ def test_env(base_env, conf_path, request):
return env
# XXX capture: capture_interface
-# XXX nameres: setUpHostFiles() / custom_profile_path / custom_profile_name
diff --git a/test/suite_nameres.py b/test/suite_nameres.py
index 3efa8be3d7..3fb38d98c3 100644
--- a/test/suite_nameres.py
+++ b/test/suite_nameres.py
@@ -9,34 +9,56 @@
#
'''Name resolution tests'''
-import config
import os.path
+import shutil
import subprocesstest
-import unittest
-
-dns_icmp_pcapng = os.path.join(config.capture_dir, 'dns+icmp.pcapng.gz')
+import fixtures
tf_str = { True: 'TRUE', False: 'FALSE' }
-def check_name_resolution(self, o_net_name, o_external_name_res, o_hosts_file, custom_profile, grep_str, fail_on_match=False):
- tshark_cmd = (config.cmd_tshark,
- '-r', dns_icmp_pcapng,
- '-o', 'nameres.network_name: ' + tf_str[o_net_name],
- '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res],
- '-o', 'nameres.hosts_file_handling: ' + tf_str[o_hosts_file],
- )
- if custom_profile:
- tshark_cmd += ('-C', config.custom_profile_name)
- self.assertRun(tshark_cmd, env=config.test_env)
- if fail_on_match:
- self.assertFalse(self.grepOutput(grep_str))
+custom_profile_name = 'Custom Profile'
+
+@fixtures.fixture
+def nameres_env(test_env, program_path, conf_path):
+ bundle_path = os.path.join(program_path, 'Wireshark.app', 'Contents', 'MacOS')
+ if os.path.isdir(bundle_path):
+ global_path = bundle_path
else:
- self.assertTrue(self.grepOutput(grep_str))
+ global_path = program_path
+ custom_profile_path = os.path.join(conf_path, 'profiles', custom_profile_name)
+ os.makedirs(custom_profile_path)
+ this_dir = os.path.dirname(__file__)
+ hosts_path_pfx = os.path.join(this_dir, 'hosts.')
+ shutil.copyfile(hosts_path_pfx + 'global', os.path.join(global_path, 'hosts'))
+ shutil.copyfile(hosts_path_pfx + 'personal', os.path.join(conf_path, 'hosts'))
+ shutil.copyfile(hosts_path_pfx + 'custom', os.path.join(custom_profile_path, 'hosts'))
+ return test_env
+
+
+@fixtures.fixture
+def check_name_resolution(cmd_tshark, capture_file, nameres_env):
+ def check_name_resolution_real(self, o_net_name, o_external_name_res, o_hosts_file, custom_profile, grep_str, fail_on_match=False):
+ tshark_cmd = (cmd_tshark,
+ '-r', capture_file('dns+icmp.pcapng.gz'),
+ '-o', 'nameres.network_name: ' + tf_str[o_net_name],
+ '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res],
+ '-o', 'nameres.hosts_file_handling: ' + tf_str[o_hosts_file],
+ )
+ if custom_profile:
+ tshark_cmd += ('-C', custom_profile_name)
+ self.assertRun(tshark_cmd, env=nameres_env)
+ if fail_on_match:
+ self.assertFalse(self.grepOutput(grep_str))
+ else:
+ self.assertTrue(self.grepOutput(grep_str))
+ return check_name_resolution_real
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
class case_name_resolution(subprocesstest.SubprocessTestCase):
- def test_name_resolution_net_t_ext_f_hosts_f_global(self):
+ def test_name_resolution_net_t_ext_f_hosts_f_global(self, check_name_resolution):
'''Name resolution, no external, no profile hosts, global profile.'''
# nameres.network_name: True
# nameres.use_external_name_resolver: False
@@ -44,7 +66,7 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Default
check_name_resolution(self, True, False, False, False, 'global-8-8-8-8')
- def test_name_resolution_net_t_ext_f_hosts_f_personal(self):
+ def test_name_resolution_net_t_ext_f_hosts_f_personal(self, check_name_resolution):
'''Name resolution, no external, no profile hosts, personal profile.'''
# nameres.network_name: True
# nameres.use_external_name_resolver: False
@@ -52,7 +74,7 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Default
check_name_resolution(self, True, False, False, False, 'personal-8-8-4-4')
- def test_name_resolution_net_t_ext_f_hosts_f_custom(self):
+ def test_name_resolution_net_t_ext_f_hosts_f_custom(self, check_name_resolution):
'''Name resolution, no external, no profile hosts, custom profile.'''
# nameres.network_name: True
# nameres_use_external_name_resolver: False
@@ -60,7 +82,7 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Custom
check_name_resolution(self, True, False, False, True, 'custom-4-2-2-2')
- def test_name_resolution_net_t_ext_f_hosts_t_global(self):
+ def test_name_resolution_net_t_ext_f_hosts_t_global(self, check_name_resolution):
'''Name resolution, no external, profile hosts, global profile.'''
# nameres.network_name: True
# nameres.use_external_name_resolver: False
@@ -68,7 +90,7 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Default
check_name_resolution(self, True, False, True, False, 'global-8-8-8-8', True)
- def test_name_resolution_net_t_ext_f_hosts_t_personal(self):
+ def test_name_resolution_net_t_ext_f_hosts_t_personal(self, check_name_resolution):
'''Name resolution, no external, profile hosts, personal profile.'''
# nameres.network_name: True
# nameres.use_external_name_resolver: False
@@ -76,7 +98,7 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Default
check_name_resolution(self, True, False, True, False, 'personal-8-8-4-4')
- def test_name_resolution_net_t_ext_f_hosts_t_custom(self):
+ def test_name_resolution_net_t_ext_f_hosts_t_custom(self, check_name_resolution):
'''Name resolution, no external, profile hosts, custom profile.'''
# nameres.network_name: True
# nameres_use_external_name_resolver: False
@@ -84,29 +106,26 @@ class case_name_resolution(subprocesstest.SubprocessTestCase):
# Profile: Custom
check_name_resolution(self, True, False, True, True, 'custom-4-2-2-2')
- def test_hosts_any(self):
- self.runProcess((config.cmd_tshark,
- '-r', dns_icmp_pcapng,
+ def test_hosts_any(self, cmd_tshark, capture_file):
+ self.runProcess((cmd_tshark,
+ '-r', capture_file('dns+icmp.pcapng.gz'),
'-qz', 'hosts',
- ),
- env=config.test_env)
+ ))
self.assertTrue(self.grepOutput('174.137.42.65\twww.wireshark.org'))
self.assertTrue(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
- def test_hosts_ipv4(self):
- self.runProcess((config.cmd_tshark,
- '-r', dns_icmp_pcapng,
+ def test_hosts_ipv4(self, cmd_tshark, capture_file):
+ self.runProcess((cmd_tshark,
+ '-r', capture_file('dns+icmp.pcapng.gz'),
'-qz', 'hosts,ipv4',
- ),
- env=config.test_env)
+ ))
self.assertTrue(self.grepOutput('174.137.42.65\twww.wireshark.org'))
self.assertFalse(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
- def test_hosts_ipv6(self):
- self.runProcess((config.cmd_tshark,
- '-r', dns_icmp_pcapng,
+ def test_hosts_ipv6(self, cmd_tshark, capture_file):
+ self.runProcess((cmd_tshark,
+ '-r', capture_file('dns+icmp.pcapng.gz'),
'-qz', 'hosts,ipv6',
- ),
- env=config.test_env)
+ ))
self.assertTrue(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
self.assertFalse(self.grepOutput('174.137.42.65\twww.wireshark.org'))