1
0

test_mac_brew_pkg.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import pytest
  7. from salt.exceptions import CommandExecutionError
  8. from salt.ext import six
  9. from tests.support.case import ModuleCase
  10. # Brew doesn't support local package installation - So, let's
  11. # Grab some small packages available online for brew
  12. ADD_PKG = "algol68g"
  13. DEL_PKG = "acme"
  14. @pytest.mark.destructive_test
  15. @pytest.mark.skip_if_not_root
  16. @pytest.mark.skip_unless_on_darwin
  17. @pytest.mark.skip_if_binaries_missing("brew")
  18. class BrewModuleTest(ModuleCase):
  19. """
  20. Integration tests for the brew module
  21. """
  22. @pytest.mark.slow_test(seconds=240) # Test takes >120 and <=240 seconds
  23. def test_brew_install(self):
  24. """
  25. Tests the installation of packages
  26. """
  27. try:
  28. self.run_function("pkg.install", [ADD_PKG])
  29. pkg_list = self.run_function("pkg.list_pkgs")
  30. try:
  31. self.assertIn(ADD_PKG, pkg_list)
  32. except AssertionError:
  33. self.run_function("pkg.remove", [ADD_PKG])
  34. raise
  35. except CommandExecutionError:
  36. self.run_function("pkg.remove", [ADD_PKG])
  37. raise
  38. @pytest.mark.slow_test(seconds=120) # Test takes >60 and <=120 seconds
  39. def test_remove(self):
  40. """
  41. Tests the removal of packages
  42. """
  43. try:
  44. # Install a package to delete - If unsuccessful, skip the test
  45. self.run_function("pkg.install", [DEL_PKG])
  46. pkg_list = self.run_function("pkg.list_pkgs")
  47. if DEL_PKG not in pkg_list:
  48. self.run_function("pkg.install", [DEL_PKG])
  49. self.skipTest("Failed to install a package to delete")
  50. # Now remove the installed package
  51. self.run_function("pkg.remove", [DEL_PKG])
  52. del_list = self.run_function("pkg.list_pkgs")
  53. self.assertNotIn(DEL_PKG, del_list)
  54. except CommandExecutionError:
  55. self.run_function("pkg.remove", [DEL_PKG])
  56. raise
  57. @pytest.mark.slow_test(seconds=120) # Test takes >60 and <=120 seconds
  58. def test_version(self):
  59. """
  60. Test pkg.version for mac. Installs a package and then checks we can get
  61. a version for the installed package.
  62. """
  63. try:
  64. self.run_function("pkg.install", [ADD_PKG])
  65. pkg_list = self.run_function("pkg.list_pkgs")
  66. version = self.run_function("pkg.version", [ADD_PKG])
  67. try:
  68. self.assertTrue(
  69. version,
  70. msg=(
  71. "version: {0} is empty,\
  72. or other issue is present".format(
  73. version
  74. )
  75. ),
  76. )
  77. self.assertIn(
  78. ADD_PKG,
  79. pkg_list,
  80. msg=(
  81. "package: {0} is not in\
  82. the list of installed packages: {1}".format(
  83. ADD_PKG, pkg_list
  84. )
  85. ),
  86. )
  87. # make sure the version is accurate and is listed in the pkg_list
  88. self.assertIn(
  89. version,
  90. six.text_type(pkg_list[ADD_PKG]),
  91. msg=(
  92. "The {0} version: {1} is \
  93. not listed in the pkg_list: {2}".format(
  94. ADD_PKG, version, pkg_list[ADD_PKG]
  95. )
  96. ),
  97. )
  98. except AssertionError:
  99. self.run_function("pkg.remove", [ADD_PKG])
  100. raise
  101. except CommandExecutionError:
  102. self.run_function("pkg.remove", [ADD_PKG])
  103. raise
  104. @pytest.mark.slow_test(seconds=120) # Test takes >60 and <=120 seconds
  105. def test_latest_version(self):
  106. """
  107. Test pkg.latest_version:
  108. - get the latest version available
  109. - install the package
  110. - get the latest version available
  111. - check that the latest version is empty after installing it
  112. """
  113. try:
  114. self.run_function("pkg.remove", [ADD_PKG])
  115. uninstalled_latest = self.run_function("pkg.latest_version", [ADD_PKG])
  116. self.run_function("pkg.install", [ADD_PKG])
  117. installed_latest = self.run_function("pkg.latest_version", [ADD_PKG])
  118. version = self.run_function("pkg.version", [ADD_PKG])
  119. try:
  120. self.assertTrue(isinstance(uninstalled_latest, six.string_types))
  121. self.assertEqual(installed_latest, version)
  122. except AssertionError:
  123. self.run_function("pkg.remove", [ADD_PKG])
  124. raise
  125. except CommandExecutionError:
  126. self.run_function("pkg.remove", [ADD_PKG])
  127. raise
  128. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  129. def test_refresh_db(self):
  130. """
  131. Integration test to ensure pkg.refresh_db works with brew
  132. """
  133. refresh_brew = self.run_function("pkg.refresh_db")
  134. self.assertTrue(refresh_brew)
  135. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  136. def test_list_upgrades(self):
  137. """
  138. Test pkg.list_upgrades: data is in the form {'name1': 'version1',
  139. 'name2': 'version2', ... }
  140. """
  141. try:
  142. upgrades = self.run_function("pkg.list_upgrades")
  143. try:
  144. self.assertTrue(isinstance(upgrades, dict))
  145. if upgrades:
  146. for name in upgrades:
  147. self.assertTrue(isinstance(name, six.string_types))
  148. self.assertTrue(isinstance(upgrades[name], six.string_types))
  149. except AssertionError:
  150. self.run_function("pkg.remove", [ADD_PKG])
  151. raise
  152. except CommandExecutionError:
  153. self.run_function("pkg.remove", [ADD_PKG])
  154. raise
  155. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  156. def test_info_installed(self):
  157. """
  158. Test pkg.info_installed: info returned has certain fields used by
  159. mac_brew.latest_version
  160. """
  161. try:
  162. self.run_function("pkg.install", [ADD_PKG])
  163. info = self.run_function("pkg.info_installed", [ADD_PKG])
  164. try:
  165. self.assertTrue(ADD_PKG in info)
  166. self.assertTrue("versions" in info[ADD_PKG])
  167. self.assertTrue("revision" in info[ADD_PKG])
  168. self.assertTrue("stable" in info[ADD_PKG]["versions"])
  169. except AssertionError:
  170. self.run_function("pkg.remove", [ADD_PKG])
  171. raise
  172. except CommandExecutionError:
  173. self.run_function("pkg.remove", [ADD_PKG])
  174. raise
  175. def tearDown(self):
  176. """
  177. Clean up after tests
  178. """
  179. pkg_list = self.run_function("pkg.list_pkgs")
  180. # Remove any installed packages
  181. if ADD_PKG in pkg_list:
  182. self.run_function("pkg.remove", [ADD_PKG])
  183. if DEL_PKG in pkg_list:
  184. self.run_function("pkg.remove", [DEL_PKG])