test_svn.py 4.0 KB

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