1
0

test_alternatives.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Integration tests for the alternatives state module
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. from tests.support.unit import skipIf
  11. from tests.support.helpers import destructiveTest
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. NO_ALTERNATIVES = False
  14. if not os.path.exists('/etc/alternatives'):
  15. NO_ALTERNATIVES = True
  16. @skipIf(NO_ALTERNATIVES, '/etc/alternatives does not exist on the system')
  17. class AlterantivesStateTest(ModuleCase, SaltReturnAssertsMixin):
  18. @destructiveTest
  19. def test_install_set_and_remove(self):
  20. ret = self.run_state('alternatives.set', name='alt-test', path='/bin/true')
  21. self.assertSaltFalseReturn(ret)
  22. ret = self.run_state('alternatives.install', name='alt-test',
  23. link='/usr/local/bin/alt-test', path='/bin/true', priority=50)
  24. self.assertSaltTrueReturn(ret)
  25. self.assertSaltStateChangesEqual(ret, '/bin/true', keys=['path'])
  26. ret = self.run_state('alternatives.install', name='alt-test',
  27. link='/usr/local/bin/alt-test', path='/bin/true', priority=50)
  28. self.assertSaltTrueReturn(ret)
  29. self.assertSaltStateChangesEqual(ret, {})
  30. ret = self.run_state('alternatives.install', name='alt-test',
  31. link='/usr/local/bin/alt-test', path='/bin/false', priority=90)
  32. self.assertSaltTrueReturn(ret)
  33. self.assertSaltStateChangesEqual(ret, '/bin/false', keys=['path'])
  34. ret = self.run_state('alternatives.set', name='alt-test', path='/bin/false')
  35. self.assertSaltTrueReturn(ret)
  36. self.assertSaltStateChangesEqual(ret, {})
  37. ret = self.run_state('alternatives.set', name='alt-test', path='/bin/true')
  38. self.assertSaltTrueReturn(ret)
  39. self.assertSaltStateChangesEqual(ret, '/bin/true', keys=['path'])
  40. ret = self.run_state('alternatives.set', name='alt-test', path='/bin/true')
  41. self.assertSaltTrueReturn(ret)
  42. self.assertSaltStateChangesEqual(ret, {})
  43. ret = self.run_state('alternatives.remove', name='alt-test', path='/bin/true')
  44. self.assertSaltTrueReturn(ret)
  45. ret = self.run_state('alternatives.remove', name='alt-test', path='/bin/false')
  46. self.assertSaltTrueReturn(ret)