1
0

test_alternatives.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.helpers import destructiveTest, slowTest
  11. from tests.support.mixins import SaltReturnAssertsMixin
  12. from tests.support.runtests import RUNTIME_VARS
  13. from tests.support.unit import skipIf
  14. NO_ALTERNATIVES = False
  15. if not os.path.exists("/etc/alternatives"):
  16. NO_ALTERNATIVES = True
  17. @skipIf(NO_ALTERNATIVES, "/etc/alternatives does not exist on the system")
  18. class AlterantivesStateTest(ModuleCase, SaltReturnAssertsMixin):
  19. @destructiveTest
  20. @slowTest
  21. def test_install_set_and_remove(self):
  22. ret = self.run_state(
  23. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  24. )
  25. self.assertSaltFalseReturn(ret)
  26. ret = self.run_state(
  27. "alternatives.install",
  28. name="alt-test",
  29. link="/usr/local/bin/alt-test",
  30. path=RUNTIME_VARS.SHELL_TRUE_PATH,
  31. priority=50,
  32. )
  33. self.assertSaltTrueReturn(ret)
  34. self.assertSaltStateChangesEqual(
  35. ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=["path"]
  36. )
  37. ret = self.run_state(
  38. "alternatives.install",
  39. name="alt-test",
  40. link="/usr/local/bin/alt-test",
  41. path=RUNTIME_VARS.SHELL_TRUE_PATH,
  42. priority=50,
  43. )
  44. self.assertSaltTrueReturn(ret)
  45. self.assertSaltStateChangesEqual(ret, {})
  46. ret = self.run_state(
  47. "alternatives.install",
  48. name="alt-test",
  49. link="/usr/local/bin/alt-test",
  50. path=RUNTIME_VARS.SHELL_FALSE_PATH,
  51. priority=90,
  52. )
  53. self.assertSaltTrueReturn(ret)
  54. self.assertSaltStateChangesEqual(
  55. ret, RUNTIME_VARS.SHELL_FALSE_PATH, keys=["path"]
  56. )
  57. ret = self.run_state(
  58. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_FALSE_PATH
  59. )
  60. self.assertSaltTrueReturn(ret)
  61. self.assertSaltStateChangesEqual(ret, {})
  62. ret = self.run_state(
  63. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  64. )
  65. self.assertSaltTrueReturn(ret)
  66. self.assertSaltStateChangesEqual(
  67. ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=["path"]
  68. )
  69. ret = self.run_state(
  70. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  71. )
  72. self.assertSaltTrueReturn(ret)
  73. self.assertSaltStateChangesEqual(ret, {})
  74. ret = self.run_state(
  75. "alternatives.remove", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  76. )
  77. self.assertSaltTrueReturn(ret)
  78. ret = self.run_state(
  79. "alternatives.remove", name="alt-test", path=RUNTIME_VARS.SHELL_FALSE_PATH
  80. )
  81. self.assertSaltTrueReturn(ret)