1
0

test_gem.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Integration tests for Ruby Gem module
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing libs
  8. from tests.support.case import ModuleCase
  9. from tests.support.unit import skipIf
  10. # Import salt libs
  11. import salt.utils.path
  12. # Import 3rd-party libs
  13. import pytest
  14. from tornado.httpclient import HTTPClient
  15. def check_status():
  16. '''
  17. Check the status of the rubygems source
  18. '''
  19. try:
  20. return HTTPClient().fetch('https://rubygems.org').code == 200
  21. except Exception: # pylint: disable=broad-except
  22. return False
  23. @pytest.mark.destructive_test
  24. @skipIf(not salt.utils.path.which('gem'), 'Gem is not available')
  25. @pytest.mark.windows_whitelisted
  26. class GemModuleTest(ModuleCase):
  27. '''
  28. Validate gem module
  29. '''
  30. def setUp(self):
  31. if check_status() is False:
  32. self.skipTest('External resource \'https://rubygems.org\' is not available')
  33. self.GEM = 'tidy'
  34. self.GEM_VER = '1.1.2'
  35. self.OLD_GEM = 'brass'
  36. self.OLD_VERSION = '1.0.0'
  37. self.NEW_VERSION = '1.2.1'
  38. self.GEM_LIST = [self.GEM, self.OLD_GEM]
  39. for name in ('GEM', 'GEM_VER', 'OLD_GEM', 'OLD_VERSION', 'NEW_VERSION', 'GEM_LIST'):
  40. self.addCleanup(delattr, self, name)
  41. def uninstall_gem():
  42. # Remove gem if it is already installed
  43. if self.run_function('gem.list', [self.GEM]):
  44. self.run_function('gem.uninstall', [self.GEM])
  45. self.addCleanup(uninstall_gem)
  46. def test_install_uninstall(self):
  47. '''
  48. gem.install
  49. gem.uninstall
  50. '''
  51. self.run_function('gem.install', [self.GEM])
  52. gem_list = self.run_function('gem.list', [self.GEM])
  53. self.assertIn(self.GEM, gem_list)
  54. self.run_function('gem.uninstall', [self.GEM])
  55. self.assertFalse(self.run_function('gem.list', [self.GEM]))
  56. def test_install_version(self):
  57. '''
  58. gem.install rake version=11.1.2
  59. '''
  60. self.run_function('gem.install', [self.GEM], version=self.GEM_VER)
  61. gem_list = self.run_function('gem.list', [self.GEM])
  62. self.assertIn(self.GEM, gem_list)
  63. self.assertIn(self.GEM_VER, gem_list[self.GEM])
  64. self.run_function('gem.uninstall', [self.GEM])
  65. self.assertFalse(self.run_function('gem.list', [self.GEM]))
  66. def test_list(self):
  67. '''
  68. gem.list
  69. '''
  70. self.run_function('gem.install', [' '.join(self.GEM_LIST)])
  71. all_ret = self.run_function('gem.list')
  72. for gem in self.GEM_LIST:
  73. self.assertIn(gem, all_ret)
  74. single_ret = self.run_function('gem.list', [self.GEM])
  75. self.assertIn(self.GEM, single_ret)
  76. self.run_function('gem.uninstall', [' '.join(self.GEM_LIST)])
  77. def test_list_upgrades(self):
  78. '''
  79. gem.list_upgrades
  80. '''
  81. # install outdated gem
  82. self.run_function('gem.install', [self.OLD_GEM], version=self.OLD_VERSION)
  83. ret = self.run_function('gem.list_upgrades')
  84. self.assertIn(self.OLD_GEM, ret)
  85. self.run_function('gem.uninstall', [self.OLD_GEM])
  86. def test_sources_add_remove(self):
  87. '''
  88. gem.sources_add
  89. gem.sources_remove
  90. '''
  91. source = 'http://production.cf.rubygems.org'
  92. self.run_function('gem.sources_add', [source])
  93. sources_list = self.run_function('gem.sources_list')
  94. self.assertIn(source, sources_list)
  95. self.run_function('gem.sources_remove', [source])
  96. sources_list = self.run_function('gem.sources_list')
  97. self.assertNotIn(source, sources_list)
  98. def test_update(self):
  99. '''
  100. gem.update
  101. '''
  102. self.run_function('gem.install', [self.OLD_GEM], version=self.OLD_VERSION)
  103. gem_list = self.run_function('gem.list', [self.OLD_GEM])
  104. self.assertEqual({self.OLD_GEM: [self.OLD_VERSION]}, gem_list)
  105. self.run_function('gem.update', [self.OLD_GEM])
  106. gem_list = self.run_function('gem.list', [self.OLD_GEM])
  107. self.assertEqual({self.OLD_GEM: [self.NEW_VERSION, self.OLD_VERSION]}, gem_list)
  108. self.run_function('gem.uninstall', [self.OLD_GEM])
  109. self.assertFalse(self.run_function('gem.list', [self.OLD_GEM]))
  110. def test_update_system(self):
  111. '''
  112. gem.update_system
  113. '''
  114. ret = self.run_function('gem.update_system')
  115. self.assertTrue(ret)