mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Keep a copy of the DEFAULT_API_OPTS and restore them after the test run
Without this copy, the settings in DEFAULT_API_OPTS was getting overridden by the new settings in the unit test. Let's copy those default settings, and then restore them at the end of the test. These tests have also been marked as destructive.
This commit is contained in:
parent
2ad07634d9
commit
fa01367599
1 changed files with 15 additions and 9 deletions
|
@ -8,7 +8,7 @@ from __future__ import absolute_import
|
|||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.helpers import destructiveTest, ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
MagicMock,
|
||||
NO_MOCK,
|
||||
|
@ -26,11 +26,6 @@ MOCK_MASTER_DEFAULT_OPTS = {
|
|||
'pidfile': '/var/run/salt-master.pid',
|
||||
'root_dir': '/'
|
||||
}
|
||||
MOCK_MASTER_CONFIG_FILE_DATA = {
|
||||
'api_pidfile': '/foo/bar/baz',
|
||||
'api_logfile': '/hello/world',
|
||||
'rest_timeout': 5
|
||||
}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
|
@ -40,7 +35,6 @@ class APIConfigTestCase(TestCase):
|
|||
'''
|
||||
|
||||
@patch('salt.config.client_config', MagicMock(return_value=MOCK_MASTER_DEFAULT_OPTS))
|
||||
@patch('salt.config.prepend_root_dir', MagicMock(return_value={}))
|
||||
def test_api_config_log_file_values(self):
|
||||
'''
|
||||
Tests the opts value of the 'log_file' after running through the
|
||||
|
@ -51,7 +45,6 @@ class APIConfigTestCase(TestCase):
|
|||
self.assertEqual(ret['log_file'], '/var/log/salt/api')
|
||||
|
||||
@patch('salt.config.client_config', MagicMock(return_value=MOCK_MASTER_DEFAULT_OPTS))
|
||||
@patch('salt.config.prepend_root_dir', MagicMock(return_value={}))
|
||||
def test_api_config_pidfile_values(self):
|
||||
'''
|
||||
Tests the opts value of the 'pidfile' after running through the
|
||||
|
@ -61,13 +54,16 @@ class APIConfigTestCase(TestCase):
|
|||
ret = salt.config.api_config('/some/fake/path')
|
||||
self.assertEqual(ret['pidfile'], '/var/run/salt-api.pid')
|
||||
|
||||
@patch('salt.config.prepend_root_dir', MagicMock(return_value={}))
|
||||
@destructiveTest
|
||||
def test_master_config_file_overrides_defaults(self):
|
||||
'''
|
||||
Tests the opts value of the api config values after running through the
|
||||
various default dict updates that should be overridden by settings in
|
||||
the user's master config file.
|
||||
'''
|
||||
# Copy DEFAULT_API_OPTS to restore after the test
|
||||
default_api_opts = salt.config.DEFAULT_API_OPTS.copy()
|
||||
|
||||
foo_dir = '/foo/bar/baz'
|
||||
hello_dir = '/hello/world'
|
||||
mock_master_config = {
|
||||
|
@ -86,6 +82,10 @@ class APIConfigTestCase(TestCase):
|
|||
self.assertEqual(ret['api_logfile'], hello_dir)
|
||||
self.assertEqual(ret['log_file'], hello_dir)
|
||||
|
||||
# Reset DEFAULT_API_OPTS settings as to not interfere with other unit tests
|
||||
salt.config.DEFAULT_API_OPTS = default_api_opts
|
||||
|
||||
@destructiveTest
|
||||
def test_api_config_prepend_root_dirs_return(self):
|
||||
'''
|
||||
Tests the opts value of the api_logfile, log_file, api_pidfile, and pidfile
|
||||
|
@ -93,6 +93,9 @@ class APIConfigTestCase(TestCase):
|
|||
values is present in the list of opts keys that should have the root_dir
|
||||
prepended when the api_config function returns the opts dictionary.
|
||||
'''
|
||||
# Copy DEFAULT_API_OPTS to restore after the test
|
||||
default_api_opts = salt.config.DEFAULT_API_OPTS.copy()
|
||||
|
||||
mock_log = '/mock/root/var/log/salt/api'
|
||||
mock_pid = '/mock/root/var/run/salt-api.pid'
|
||||
|
||||
|
@ -107,6 +110,9 @@ class APIConfigTestCase(TestCase):
|
|||
self.assertEqual(ret['api_pidfile'], mock_pid)
|
||||
self.assertEqual(ret['pidfile'], mock_pid)
|
||||
|
||||
# Reset DEFAULT_API_OPTS settings as to not interfere with other unit tests
|
||||
salt.config.DEFAULT_API_OPTS = default_api_opts
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue