1
0

test_svn.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the SVN state
  4. """
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. import shutil
  9. import socket
  10. import pytest
  11. from tests.support.case import ModuleCase
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. # Import Salt Testing libs
  14. from tests.support.runtests import RUNTIME_VARS
  15. class SvnTest(ModuleCase, SaltReturnAssertsMixin):
  16. """
  17. Validate the svn state
  18. """
  19. def setUp(self):
  20. super(SvnTest, self).setUp()
  21. if not self.run_function("cmd.has_exec", ["svn"]):
  22. self.skipTest("The executable 'svn' is not available.")
  23. self.__domain = "svn.apache.org"
  24. try:
  25. if hasattr(socket, "setdefaulttimeout"):
  26. # 10 second dns timeout
  27. socket.setdefaulttimeout(10)
  28. socket.gethostbyname(self.__domain)
  29. except socket.error:
  30. msg = "error resolving {0}, possible network issue?"
  31. self.skipTest(msg.format(self.__domain))
  32. self.target = os.path.join(RUNTIME_VARS.TMP, "apache_http_test_repo")
  33. self.name = "http://{0}/repos/asf/httpd/httpd/trunk/test/".format(self.__domain)
  34. self.new_rev = "1456987"
  35. def tearDown(self):
  36. shutil.rmtree(self.target, ignore_errors=True)
  37. # Reset the dns timeout after the test is over
  38. socket.setdefaulttimeout(None)
  39. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  40. def test_latest(self):
  41. """
  42. svn.latest
  43. """
  44. ret = self.run_state(
  45. "svn.latest", name=self.name, rev=self.new_rev, target=self.target,
  46. )
  47. self.assertSaltTrueReturn(ret)
  48. self.assertTrue(os.path.isdir(os.path.join(self.target, ".svn")))
  49. self.assertSaltStateChangesEqual(ret, self.name, keys=["new"])
  50. self.assertSaltStateChangesEqual(ret, self.new_rev, keys=["revision"])
  51. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  52. def test_latest_failure(self):
  53. """
  54. svn.latest
  55. """
  56. ret = self.run_state(
  57. "svn.latest",
  58. name="https://youSpelledApacheWrong.com/repo/asf/httpd/trunk/",
  59. rev=self.new_rev,
  60. target=self.target,
  61. )
  62. self.assertSaltFalseReturn(ret)
  63. self.assertFalse(os.path.isdir(os.path.join(self.target, ".svn")))
  64. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  65. def test_latest_empty_dir(self):
  66. """
  67. svn.latest
  68. """
  69. if not os.path.isdir(self.target):
  70. os.mkdir(self.target)
  71. ret = self.run_state(
  72. "svn.latest", name=self.name, rev=self.new_rev, target=self.target,
  73. )
  74. self.assertSaltTrueReturn(ret)
  75. self.assertTrue(os.path.isdir(os.path.join(self.target, ".svn")))
  76. def no_test_latest_existing_repo(self):
  77. """
  78. svn.latest against existing repository
  79. """
  80. current_rev = "1442865"
  81. cwd, basename = os.path.split(self.target)
  82. opts = ("-r", current_rev)
  83. out = self.run_function(
  84. "svn.checkout", [cwd, self.name, basename, None, None, opts]
  85. )
  86. assert out
  87. ret = self.run_state(
  88. "svn.latest", name=self.name, rev=self.new_rev, target=self.target,
  89. )
  90. self.assertSaltTrueReturn(ret)
  91. self.assertSaltStateChangesEqual(
  92. ret, "{0} => {1}".format(current_rev, self.new_rev), keys=["revision"]
  93. )
  94. self.assertTrue(os.path.isdir(os.path.join(self.target, ".svn")))
  95. def no_test_latest_existing_repo_no_rev_change(self):
  96. """
  97. svn.latest against existing repository
  98. """
  99. current_rev = self.new_rev
  100. cwd, basename = os.path.split(self.target)
  101. opts = ("-r", current_rev)
  102. out = self.run_function(
  103. "svn.checkout", [cwd, self.name, basename, None, None, opts]
  104. )
  105. assert out
  106. ret = self.run_state(
  107. "svn.latest", name=self.name, rev=self.new_rev, target=self.target,
  108. )
  109. self.assertSaltTrueReturn(ret)
  110. self.assertSaltStateChangesEqual(ret, {})
  111. self.assertTrue(os.path.isdir(os.path.join(self.target, ".svn")))