Implement error handling test for listing upgrades

This commit is contained in:
Bo Maryniuk 2016-02-24 11:55:34 +01:00
parent 080b4ee617
commit 4d38d318f4

View file

@ -14,6 +14,8 @@ from salttesting.mock import (
NO_MOCK,
NO_MOCK_REASON
)
from salt.exceptions import CommandExecutionError
import os
from salttesting.helpers import ensure_in_syspath
@ -40,6 +42,33 @@ class ZypperTestCase(TestCase):
Test cases for salt.modules.zypper
'''
def test_list_upgrades_error_handling(self):
'''
Test error handling in the list package upgrades.
:return:
'''
# Test handled errors
ref_out = {
'stderr': 'Some handled zypper internal error',
'retcode': 1
}
with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}):
try:
zypper.list_upgrades(refresh=False)
except CommandExecutionError as error:
assert (error.message == ref_out['stderr'])
# Test unhandled error
ref_out = {
'retcode': 1
}
with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}):
try:
zypper.list_upgrades(refresh=False)
except CommandExecutionError as error:
assert (error.message == 'Zypper returned non-zero system exit. See Zypper logs for more details.')
def test_list_products(self):
'''
List products test.