mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
listen and listen_in requisite tests
This commit is contained in:
parent
1437c9a1f5
commit
c3f786c966
3 changed files with 78 additions and 2 deletions
|
@ -0,0 +1,21 @@
|
|||
successful_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Successful Change"
|
||||
- listen_in:
|
||||
- cmd: test_listening_change_state
|
||||
|
||||
# mock is installed with salttesting, so it should already be
|
||||
# present on the system, resulting in no changes
|
||||
non_changing_state:
|
||||
pip.installed:
|
||||
- name: mock
|
||||
- listen_in:
|
||||
- cmd: test_listening_non_changing_state
|
||||
|
||||
test_listening_change_state:
|
||||
cmd.run:
|
||||
- name: echo "Listening State"
|
||||
|
||||
test_listening_non_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Only run once"
|
|
@ -0,0 +1,21 @@
|
|||
successful_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Successful Change"
|
||||
|
||||
# mock is installed with salttesting, so it should already be
|
||||
# present on the system, resulting in no changes
|
||||
non_changing_state:
|
||||
pip.installed:
|
||||
- name: mock
|
||||
|
||||
test_listening_change_state:
|
||||
cmd.run:
|
||||
- name: echo "Listening State"
|
||||
- listen:
|
||||
- cmd: successful_changing_state
|
||||
|
||||
test_listening_non_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Only run once"
|
||||
- listen:
|
||||
- pip: non_changing_state
|
|
@ -891,7 +891,7 @@ fi
|
|||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onfail_simple')
|
||||
|
||||
# First, test the restul of the state run when a failure is expected to happen
|
||||
# First, test the result of the state run when a failure is expected to happen
|
||||
test_data = state_run['cmd_|-test_failing_state_|-echo "Success!"_|-run']['comment']
|
||||
expected_result = 'Command "echo "Success!"" run'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
@ -909,7 +909,7 @@ fi
|
|||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onfail_in_simple')
|
||||
|
||||
# First, test the restul of the state run when a failure is expected to happen
|
||||
# First, test the result of the state run when a failure is expected to happen
|
||||
test_data = state_run['cmd_|-test_failing_state_|-echo "Success!"_|-run']['comment']
|
||||
expected_result = 'Command "echo "Success!"" run'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
@ -919,6 +919,40 @@ fi
|
|||
expected_result = 'State was not run because onfail req did not change'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
# listen tests
|
||||
|
||||
def test_listen_requisite(self):
|
||||
'''
|
||||
Tests a simple state using the listen requisite
|
||||
'''
|
||||
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.listen_simple')
|
||||
|
||||
# First, test the result of the state run when a listener is expected to trigger
|
||||
listener_state = 'cmd_|-listener_test_listening_change_state_|-echo "Listening State"_|-mod_watch'
|
||||
self.assertIn(listener_state, state_run)
|
||||
|
||||
# Then, test the result of the state run when a listener should not trigger
|
||||
absent_state = 'cmd_|-listener_test_listening_non_changing_state_|-echo "Only run once"_|-mod_watch'
|
||||
self.assertNotIn(absent_state, state_run)
|
||||
|
||||
def test_listen_in_requisite(self):
|
||||
'''
|
||||
Tests a simple state using the listen_in requisite
|
||||
'''
|
||||
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.listen_in_simple')
|
||||
|
||||
# First, test the result of the state run when a listener is expected to trigger
|
||||
listener_state = 'cmd_|-listener_test_listening_change_state_|-echo "Listening State"_|-mod_watch'
|
||||
self.assertIn(listener_state, state_run)
|
||||
|
||||
# Then, test the result of the state run when a listener should not trigger
|
||||
absent_state = 'cmd_|-listener_test_listening_non_changing_state_|-echo "Only run once"_|-mod_watch'
|
||||
self.assertNotIn(absent_state, state_run)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue