diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2015-01-23 23:17:34 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2015-07-07 20:56:57 +0100 |
commit | b1f3b3373e8ef3e94238760a3e7e78d95c564260 (patch) | |
tree | 8eb1d1ce9773f84739facf96cfbfb76bd38a2cf2 /tests | |
parent | 3eed62e132f67930bb1cf5c9eaa5927083011043 (diff) | |
download | sos-b1f3b3373e8ef3e94238760a3e7e78d95c564260.tar.gz |
[plugins] prefix target paths with self.sysroot
Prefix copyspecs with self.sysroot when using an alternate root
path. Prefixes are applied before expanding copyspecs and the
prefixed paths are stored as the 'srcpath' attribute in the
archive. Destination paths in the report archive do not include
the prefix.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/option_tests.py | 3 | ||||
-rw-r--r-- | tests/plugin_tests.py | 57 |
2 files changed, 40 insertions, 20 deletions
diff --git a/tests/option_tests.py b/tests/option_tests.py index fe37ccfe..e8a26e2d 100644 --- a/tests/option_tests.py +++ b/tests/option_tests.py @@ -8,10 +8,11 @@ class GlobalOptionTest(unittest.TestCase): def setUp(self): self.commons = { + 'sysroot': '/', 'global_plugin_options': { 'test_option': 'foobar', 'baz': None, - 'empty_global': True, + 'empty_global': True }, } self.plugin = Plugin(self.commons) diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index e30ded5c..14d3b49c 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -127,50 +127,53 @@ class PluginToolTests(unittest.TestCase): class PluginTests(unittest.TestCase): + sysroot = os.getcwd() + def setUp(self): self.mp = MockPlugin({ - 'cmdlineopts': MockOptions() + 'cmdlineopts': MockOptions(), + 'sysroot': self.sysroot }) self.mp.archive = MockArchive() def test_plugin_default_name(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.name(), "mockplugin") def test_plugin_set_name(self): - p = NamedMockPlugin({}) + p = NamedMockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.name(), "testing") def test_plugin_no_descrip(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_description(), "<no description available>") def test_plugin_no_descrip(self): - p = NamedMockPlugin({}) + p = NamedMockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_description(), "This plugin has a description.") def test_set_plugin_option(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) p.set_option("opt", "testing") self.assertEquals(p.get_option("opt"), "testing") def test_set_nonexistant_plugin_option(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertFalse(p.set_option("badopt", "testing")) def test_get_nonexistant_plugin_option(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_option("badopt"), 0) def test_get_unset_plugin_option(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_option("opt"), 0) def test_get_unset_plugin_option_with_default(self): # this shows that even when we pass in a default to get, # we'll get the option's default as set in the plugin # this might not be what we really want - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_option("opt", True), True) def test_get_unset_plugin_option_with_default_not_none(self): @@ -178,20 +181,20 @@ class PluginTests(unittest.TestCase): # if the plugin default is not None # we'll get the option's default as set in the plugin # this might not be what we really want - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_option("opt2", True), False) def test_get_option_as_list_plugin_option(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) p.set_option("opt", "one,two,three") self.assertEquals(p.get_option_as_list("opt"), ['one', 'two', 'three']) def test_get_option_as_list_plugin_option_default(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) self.assertEquals(p.get_option_as_list("opt", default=[]), []) def test_get_option_as_list_plugin_option_not_list(self): - p = MockPlugin({}) + p = MockPlugin({'sysroot': self.sysroot}) p.set_option("opt", "testing") self.assertEquals(p.get_option_as_list("opt"), ['testing']) @@ -205,7 +208,8 @@ class PluginTests(unittest.TestCase): def test_copy_dir_forbidden_path(self): p = ForbiddenMockPlugin({ - 'cmdlineopts': MockOptions() + 'cmdlineopts': MockOptions(), + 'sysroot': self.sysroot }) p.archive = MockArchive() p.setup() @@ -219,12 +223,18 @@ class AddCopySpecTests(unittest.TestCase): def setUp(self): self.mp = MockPlugin({ - 'cmdlineopts': MockOptions() + 'cmdlineopts': MockOptions(), + 'sysroot': os.getcwd() }) self.mp.archive = MockArchive() def assert_expect_paths(self): - self.assertEquals(self.mp.copy_paths, self.expect_paths) + def pathmunge(path): + if path[0] == '/': + path = path[1:] + return os.path.join(self.mp.sysroot, path) + expected_paths = set(map(pathmunge, self.expect_paths)) + self.assertEquals(self.mp.copy_paths, expected_paths) # add_copy_spec() @@ -242,6 +252,7 @@ class AddCopySpecTests(unittest.TestCase): # add_copy_spec_limit() def test_single_file_over_limit(self): + self.mp.sysroot = '/' fn = create_file(2) # create 2MB file, consider a context manager self.mp.add_copy_spec_limit(fn, 1) content, fname = self.mp.copy_strings[0] @@ -252,10 +263,12 @@ class AddCopySpecTests(unittest.TestCase): os.unlink(fn) def test_bad_filename(self): + self.mp.sysroot = '/' self.assertFalse(self.mp.add_copy_spec_limit('', 1)) self.assertFalse(self.mp.add_copy_spec_limit(None, 1)) def test_glob_file_over_limit(self): + self.mp.sysroot = '/' # assume these are in /tmp fn = create_file(2) fn2 = create_file(2) @@ -271,7 +284,10 @@ class AddCopySpecTests(unittest.TestCase): class CheckEnabledTests(unittest.TestCase): def setUp(self): - self.mp = EnablerPlugin({'policy': sos.policies.load()}) + self.mp = EnablerPlugin({ + 'policy': sos.policies.load(), + 'sysroot': os.getcwd() + }) def test_checks_for_file(self): f = j("tail_test.txt") @@ -296,7 +312,8 @@ class RegexSubTests(unittest.TestCase): def setUp(self): self.mp = MockPlugin({ - 'cmdlineopts': MockOptions() + 'cmdlineopts': MockOptions(), + 'sysroot': os.getcwd() }) self.mp.archive = MockArchive() @@ -310,6 +327,8 @@ class RegexSubTests(unittest.TestCase): self.assertEquals(0, replacements) def test_replacements(self): + # test uses absolute paths + self.mp.sysroot = '/' self.mp.add_copy_spec(j("tail_test.txt")) self.mp.collect() replacements = self.mp.do_file_sub(j("tail_test.txt"), r"(tail)", "foobar") |