mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add integration test for depends decorator
This commit is contained in:
parent
caa3cc1007
commit
394410e2b0
1 changed files with 53 additions and 0 deletions
|
@ -31,6 +31,59 @@ from salt.config import minion_config
|
|||
|
||||
from salt.loader import LazyLoader, _module_dirs, grains
|
||||
|
||||
loader_template = '''
|
||||
import os
|
||||
from salt.utils.decorators import depends
|
||||
|
||||
@depends('os')
|
||||
def loaded():
|
||||
return True
|
||||
|
||||
@depends('non_existantmodulename')
|
||||
def not_loaded():
|
||||
return True
|
||||
'''
|
||||
|
||||
class LazyLoaderTest(TestCase):
|
||||
'''
|
||||
Test the loader
|
||||
'''
|
||||
module_name = 'lazyloadertest'
|
||||
|
||||
def setUp(self):
|
||||
self.opts = minion_config(None)
|
||||
self.opts['disable_modules'] = ['pillar']
|
||||
self.opts['grains'] = grains(self.opts)
|
||||
|
||||
# Setup the module
|
||||
self.module_dir = tempfile.mkdtemp(dir=tests.integration.TMP)
|
||||
self.module_file = os.path.join(self.module_dir,
|
||||
'{0}.py'.format(self.module_name))
|
||||
with open(self.module_file, 'w') as fh:
|
||||
fh.write(loader_template)
|
||||
fh.flush()
|
||||
os.fsync(fh.fileno())
|
||||
|
||||
# Invoke the loader
|
||||
self.loader = LazyLoader([self.module_dir], self.opts, tag='module')
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.module_dir)
|
||||
|
||||
def test_depends(self):
|
||||
'''
|
||||
Test that the depends decorator works properly
|
||||
'''
|
||||
# Make sure depends correctly allowed a function to load. If this
|
||||
# results in a KeyError, the decorator is broken.
|
||||
self.assertTrue(
|
||||
inspect.isfunction(
|
||||
self.loader[self.module_name + '.loaded']
|
||||
)
|
||||
)
|
||||
# Make sure depends correctly kept a function from loading
|
||||
self.assertTrue(self.module_name + '.not_loaded' not in self.loader)
|
||||
|
||||
|
||||
class LazyLoaderVirtualEnabledTest(TestCase):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue