aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2018-01-03 12:38:50 -0500
committerBryn M. Reeves <bmr@redhat.com>2018-04-17 15:36:24 +0100
commit5d41100f9d289121467b436f124f91137bc7c621 (patch)
treeb80031f2f9c0ad3fb40f139cb41165352447c7f0 /tests
parent333918cba972db00d524074491593a2b080a153c (diff)
downloadsos-5d41100f9d289121467b436f124f91137bc7c621.tar.gz
[Plugin] Make Plugin.policy an object instead of a function
Moves Plugin.policy to be an object for plugins instead of a function, making it easier to leverage the active policy within sos plugins. Resolves: #1179 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/option_tests.py3
-rw-r--r--tests/plugin_tests.py39
2 files changed, 28 insertions, 14 deletions
diff --git a/tests/option_tests.py b/tests/option_tests.py
index e8a26e2d..a4267e2e 100644
--- a/tests/option_tests.py
+++ b/tests/option_tests.py
@@ -3,12 +3,15 @@
import unittest
from sos.plugins import Plugin
+from sos.policies import LinuxPolicy
+
class GlobalOptionTest(unittest.TestCase):
def setUp(self):
self.commons = {
'sysroot': '/',
+ 'policy': LinuxPolicy(),
'global_plugin_options': {
'test_option': 'foobar',
'baz': None,
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index 0ccea73b..60d59d6f 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -12,6 +12,7 @@ except:
from sos.plugins import Plugin, regex_findall, _mangle_command
from sos.archive import TarFileArchive
+from sos.policies import LinuxPolicy
import sos.policies
PATH = os.path.dirname(__file__)
@@ -133,48 +134,55 @@ class PluginTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': self.sysroot
})
self.mp.archive = MockArchive()
def test_plugin_default_name(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.name(), "mockplugin")
def test_plugin_set_name(self):
- p = NamedMockPlugin({'sysroot': self.sysroot})
+ p = NamedMockPlugin({
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
+ })
self.assertEquals(p.name(), "testing")
def test_plugin_no_descrip(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_description(), "<no description available>")
def test_plugin_no_descrip(self):
- p = NamedMockPlugin({'sysroot': self.sysroot})
+ p = NamedMockPlugin({
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
+ })
self.assertEquals(p.get_description(), "This plugin has a description.")
def test_set_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option("opt"), "testing")
def test_set_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertFalse(p.set_option("badopt", "testing"))
def test_get_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("badopt"), 0)
def test_get_unset_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
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({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("opt", True), True)
def test_get_unset_plugin_option_with_default_not_none(self):
@@ -182,20 +190,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({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("opt2", True), False)
def test_get_option_as_list_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
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({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option_as_list("opt", default=[]), [])
def test_get_option_as_list_plugin_option_not_list(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option_as_list("opt"), ['testing'])
@@ -210,7 +218,8 @@ class PluginTests(unittest.TestCase):
def test_copy_dir_forbidden_path(self):
p = ForbiddenMockPlugin({
'cmdlineopts': MockOptions(),
- 'sysroot': self.sysroot
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
})
p.archive = MockArchive()
p.setup()
@@ -225,6 +234,7 @@ class AddCopySpecTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': os.getcwd()
})
self.mp.archive = MockArchive()
@@ -328,6 +338,7 @@ class RegexSubTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': os.getcwd()
})
self.mp.archive = MockArchive()