onfail and onfail_in requisite tests

This commit is contained in:
rallytime 2015-02-19 14:35:26 -07:00
parent 208b4906d8
commit 1437c9a1f5
3 changed files with 77 additions and 1 deletions

View file

@ -0,0 +1,19 @@
failing_state:
cmd.run:
- name: asdf
- onfail_in:
- cmd: test_failing_state
non_failing_state:
cmd.run:
- name: echo "Non-failing state"
- onfail_in:
- cmd: test_non_failing_state
test_failing_state:
cmd.run:
- name: echo "Success!"
test_non_failing_state:
cmd.run:
- name: echo "Should not run"

View file

@ -0,0 +1,19 @@
failing_state:
cmd.run:
- name: asdf
non_failing_state:
cmd.run:
- name: echo "Non-failing state"
test_failing_state:
cmd.run:
- name: echo "Success!"
- onfail:
- cmd: failing_state
test_non_failing_state:
cmd.run:
- name: echo "Should not run"
- onfail:
- cmd: non_failing_state

View file

@ -876,11 +876,49 @@ fi
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
# Then, test the result 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)
# onfail tests
def test_onfail_requisite(self):
'''
Tests a simple state using the onfail requisite
'''
# 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
test_data = state_run['cmd_|-test_failing_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 a failure is not expected to happen
test_data = state_run['cmd_|-test_non_failing_state_|-echo "Should not run"_|-run']['comment']
expected_result = 'State was not run because onfail req did not change'
self.assertIn(expected_result, test_data)
def test_onfail_in_requisite(self):
'''
Tests a simple state using the onfail_in requisite
'''
# 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
test_data = state_run['cmd_|-test_failing_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 a failure is not expected to happen
test_data = state_run['cmd_|-test_non_failing_state_|-echo "Should not run"_|-run']['comment']
expected_result = 'State was not run because onfail req did not change'
self.assertIn(expected_result, test_data)
if __name__ == '__main__':
from integration import run_tests