mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Onchanges and onchanges_in requisite tests!
This commit is contained in:
parent
8f0e80bd66
commit
208b4906d8
3 changed files with 66 additions and 6 deletions
|
@ -0,0 +1,21 @@
|
|||
changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Changed!"
|
||||
- onchanges_in:
|
||||
- cmd: test_changes_expected
|
||||
|
||||
# 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
|
||||
- onchanges_in:
|
||||
- cmd: test_changes_not_expected
|
||||
|
||||
test_changes_expected:
|
||||
cmd.run:
|
||||
- name: echo "Success!"
|
||||
|
||||
test_changes_not_expected:
|
||||
cmd.run:
|
||||
- name: echo "Should not run"
|
|
@ -1,9 +1,21 @@
|
|||
changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Changed!"
|
||||
- onchanges:
|
||||
- cmd: state_to_run
|
||||
|
||||
state_to_run:
|
||||
# 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_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Success!"
|
||||
- onchanges:
|
||||
- cmd: changing_state
|
||||
|
||||
test_non_changing_state:
|
||||
cmd.run:
|
||||
- name: echo "Should not run"
|
||||
- onchanges:
|
||||
- pip: non_changing_state
|
||||
|
|
|
@ -849,10 +849,37 @@ fi
|
|||
'''
|
||||
Tests a simple state using the onchanges requisite
|
||||
'''
|
||||
ret = self.run_function('state.sls', mods='requisites.onchanges_simple')
|
||||
expected_result = 'Command "echo "Success!"" run'
|
||||
|
||||
self.assertIn(expected_result, ret['cmd_|-state_to_run_|-echo "Success!"_|-run']['comment'])
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onchanges_simple')
|
||||
|
||||
# First, test the result of the state run when changes are expected to happen
|
||||
test_data = state_run['cmd_|-test_changing_state_|-echo "Success!"_|-run']['comment']
|
||||
expected_result = 'Command "echo "Success!"" run'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
# Then, test the result of the state run when changes are not expected to happen
|
||||
test_data = state_run['cmd_|-test_non_changing_state_|-echo "Should not run"_|-run']['comment']
|
||||
expected_result = 'State was not run because onchanges req did not change'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
def test_onchanges_in_requisite(self):
|
||||
'''
|
||||
Tests a simple state using the onchanges_in requisite
|
||||
'''
|
||||
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onchanges_in_simple')
|
||||
|
||||
# First, test the result of the state run of when changes are expected to happen
|
||||
test_data = state_run['cmd_|-test_changes_expected_|-echo "Success!"_|-run']['comment']
|
||||
expected_result = 'Command "echo "Success!"" run'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
# Then, test the restul of the state run when changes are not expected to happen
|
||||
test_data = state_run['cmd_|-test_changes_not_expected_|-echo "Should not run"_|-run']['comment']
|
||||
expected_result = 'State was not run because onchanges req did not change'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue