mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Laying the groundwork for overstate unit testing.
This commit is contained in:
parent
6ae19c315c
commit
93129d8758
83
tests/unit/overstate_test.py
Normal file
83
tests/unit/overstate_test.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
:codauthor: :email:`Mike Place <mp@saltstack.com>`
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Import Salt Testing libs
|
||||||
|
from salttesting import skipIf, TestCase
|
||||||
|
from salttesting.helpers import ensure_in_syspath
|
||||||
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch, mock_open, call
|
||||||
|
ensure_in_syspath('../')
|
||||||
|
|
||||||
|
# Import salt libs
|
||||||
|
import salt.overstate
|
||||||
|
|
||||||
|
opts = {'file_roots': {},
|
||||||
|
'conf_file': ''}
|
||||||
|
|
||||||
|
overstate_sls = {
|
||||||
|
'mysql': {
|
||||||
|
'match': 'db*',
|
||||||
|
'sls': {
|
||||||
|
'mysql.server', 'drbd'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'webservers': {
|
||||||
|
'match': 'web*',
|
||||||
|
'require': ['mysql']
|
||||||
|
},
|
||||||
|
'all': {
|
||||||
|
'match': '*',
|
||||||
|
'require': {
|
||||||
|
'mysql', 'webservers'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
class OverstateTestCase(TestCase):
|
||||||
|
@patch('salt.client.LocalClient.cmd')
|
||||||
|
def test__stage_list(self, local_client_mock):
|
||||||
|
overstate = salt.overstate.OverState(opts)
|
||||||
|
overstate._stage_list(['test1', 'test2'])
|
||||||
|
local_client_mock.assert_called_with('test1 or test2', 'test.ping', expr_form='compound')
|
||||||
|
|
||||||
|
# @skipIf(True, "Do not run this test! It exposes a memory leak inside pyyaml: https://bitbucket.org/xi/pyyaml/issue/24")
|
||||||
|
# def test__names(self):
|
||||||
|
# y = 'a'
|
||||||
|
# mopen = mock_open(read_data=y)
|
||||||
|
# with patch('salt.utils.fopen', mopen, create=True):
|
||||||
|
# overstate = salt.overstate.OverState(opts, overstate='a')
|
||||||
|
|
||||||
|
def test__names(self):
|
||||||
|
overstate = salt.overstate.OverState(opts)
|
||||||
|
overstate.over = overstate._OverState__sort_stages(overstate_sls)
|
||||||
|
self.assertEqual({'webservers', 'all', 'mysql'}, overstate._names())
|
||||||
|
|
||||||
|
def test_get_stage(self):
|
||||||
|
overstate = salt.overstate.OverState(opts)
|
||||||
|
overstate.over = overstate._OverState__sort_stages(overstate_sls)
|
||||||
|
ret = overstate.get_stage('mysql')
|
||||||
|
self.assertDictEqual({'mysql': {'match': 'db*', 'sls': {'drbd', 'mysql.server'}}}, ret)
|
||||||
|
|
||||||
|
@patch('salt.overstate.OverState.call_stage')
|
||||||
|
def test_stages(self, call_stage_mock):
|
||||||
|
'''
|
||||||
|
This is a very basic test and needs expansion, since call_stage is mocked!
|
||||||
|
'''
|
||||||
|
overstate = salt.overstate.OverState(opts)
|
||||||
|
overstate.over = overstate._OverState__sort_stages(overstate_sls)
|
||||||
|
overstate.stages()
|
||||||
|
expected_calls = [call('all', {'require': {'webservers', 'mysql'}, 'match': '*'}),
|
||||||
|
call('mysql', {'match': 'db*', 'sls': {'drbd', 'mysql.server'}}),
|
||||||
|
call('webservers', {'require': ['mysql'], 'match': 'web*'})]
|
||||||
|
call_stage_mock.assert_has_calls(expected_calls, any_order=False)
|
||||||
|
|
||||||
|
# @patch('salt.overstate.OverState.call_stage')
|
||||||
|
# def test_call_stage(self, call_stage_mock):
|
||||||
|
# overstate = salt.overstate.OverState(opts)
|
||||||
|
# overstate.over = overstate._OverState__sort_stages(overstate_sls)
|
||||||
|
# overstate.call_stage('all', {'require': {'webservers', 'mysql'}, 'match': '*'})
|
||||||
|
# overstate.call_stage('mysql', {'match': 'db*', 'sls': {'drbd', 'mysql.server'}})
|
||||||
|
# overstate.call_stage({'require': ['mysql'], 'match': 'web*'})
|
Loading…
Reference in New Issue
Block a user