mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #35081 from jf/unit-tests-for-sys.list_modules_functions
Unit tests in place of integration tests for sys.list_{functions,modules}
This commit is contained in:
commit
91f7cc4a41
@ -19,60 +19,6 @@ class SysModuleTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the sys module
|
||||
'''
|
||||
def test_list_functions(self):
|
||||
'''
|
||||
sys.list_functions
|
||||
'''
|
||||
# Get all functions
|
||||
funcs = self.run_function('sys.list_functions')
|
||||
self.assertIn('hosts.list_hosts', funcs)
|
||||
self.assertIn('pkg.install', funcs)
|
||||
|
||||
# Just sysctl
|
||||
funcs = self.run_function('sys.list_functions', ('sysctl',))
|
||||
self.assertNotIn('sys.doc', funcs)
|
||||
self.assertIn('sysctl.get', funcs)
|
||||
|
||||
# Just sys
|
||||
funcs = self.run_function('sys.list_functions', ('sys.',))
|
||||
self.assertNotIn('sysctl.get', funcs)
|
||||
self.assertIn('sys.doc', funcs)
|
||||
|
||||
# Staring with sys
|
||||
funcs = self.run_function('sys.list_functions', ('sys',))
|
||||
self.assertNotIn('sysctl.get', funcs)
|
||||
self.assertIn('sys.doc', funcs)
|
||||
|
||||
def test_list_modules(self):
|
||||
'''
|
||||
sys.list_modules
|
||||
'''
|
||||
mods = self.run_function('sys.list_modules')
|
||||
self.assertTrue('hosts' in mods)
|
||||
self.assertTrue('pkg' in mods)
|
||||
|
||||
def test_list_modules_with_arg_glob(self):
|
||||
'''
|
||||
sys.list_modules u*
|
||||
|
||||
Tests getting the list of modules with 'u*', and looking for the
|
||||
"user" module
|
||||
'''
|
||||
mods = self.run_function('sys.list_modules', ['u*'])
|
||||
self.assertNotIn('bigip', mods)
|
||||
self.assertIn('user', mods)
|
||||
|
||||
def test_list_modules_with_arg_exact_match(self):
|
||||
'''
|
||||
sys.list_modules user
|
||||
|
||||
Tests getting the list of modules looking for the "user" module with
|
||||
an exact match of 'user' being passed at the CLI instead of something
|
||||
with '*'.
|
||||
'''
|
||||
mods = self.run_function('sys.list_modules', ['user'])
|
||||
self.assertEqual(mods, ['user'])
|
||||
|
||||
def test_valid_docs(self):
|
||||
'''
|
||||
Make sure no functions are exposed that don't have valid docstrings
|
||||
|
@ -21,9 +21,24 @@ ensure_in_syspath('../../')
|
||||
# Import Salt Libs
|
||||
from salt.modules import sysmod
|
||||
|
||||
modules = set()
|
||||
functions = [
|
||||
'sys.doc', 'sys.list_functions', 'sys.list_modules',
|
||||
'sysctl.get', 'sysctl.show',
|
||||
'system.halt', 'system.reboot',
|
||||
|
||||
'udev.name', 'udev.path',
|
||||
'user.add', 'user.info', 'user.rename',
|
||||
]
|
||||
|
||||
sysmod.__salt__ = {}
|
||||
sysmod.__opts__ = {}
|
||||
|
||||
for func in functions:
|
||||
sysmod.__salt__[func] = None
|
||||
modules.add(func.split('.')[0])
|
||||
modules = sorted(list(modules))
|
||||
|
||||
|
||||
class Mockstate(object):
|
||||
"""
|
||||
@ -97,7 +112,7 @@ class SysmodTestCase(TestCase):
|
||||
'''
|
||||
Test if it return the docstrings for all modules.
|
||||
'''
|
||||
self.assertDictEqual(sysmod.doc(), {})
|
||||
self.assertDictEqual(sysmod.doc(), sysmod.__salt__)
|
||||
|
||||
# 'state_doc' function tests: 1
|
||||
|
||||
@ -145,9 +160,19 @@ class SysmodTestCase(TestCase):
|
||||
'''
|
||||
Test if it list the functions for all modules.
|
||||
'''
|
||||
self.assertListEqual(sysmod.list_functions(), [])
|
||||
self.assertListEqual(sysmod.list_functions(), functions)
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys'), [])
|
||||
self.assertListEqual(sysmod.list_modules('nonexist'), [])
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys.'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys.l'), [])
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys.list*'), ['sys.list_functions', 'sys.list_modules'])
|
||||
|
||||
self.assertListEqual(sysmod.list_functions('sys*'), ['sys.doc', 'sys.list_functions', 'sys.list_modules', 'sysctl.get', 'sysctl.show', 'system.halt', 'system.reboot'])
|
||||
|
||||
# 'list_modules' function tests: 1
|
||||
|
||||
@ -155,9 +180,13 @@ class SysmodTestCase(TestCase):
|
||||
'''
|
||||
Test if it list the modules loaded on the minion
|
||||
'''
|
||||
self.assertListEqual(sysmod.list_modules(), [])
|
||||
self.assertListEqual(sysmod.list_modules(), modules)
|
||||
|
||||
self.assertListEqual(sysmod.list_modules('s*'), [])
|
||||
self.assertListEqual(sysmod.list_modules('nonexist'), [])
|
||||
|
||||
self.assertListEqual(sysmod.list_modules('user'), ['user'])
|
||||
|
||||
self.assertListEqual(sysmod.list_modules('s*'), ['sys', 'sysctl', 'system'])
|
||||
|
||||
# 'reload_modules' function tests: 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user