1
0

test_saltcheck.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test the saltcheck module
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import slowTest
  8. class SaltcheckModuleTest(ModuleCase):
  9. """
  10. Test the saltcheck module
  11. """
  12. @slowTest
  13. def test_saltcheck_run(self):
  14. """
  15. saltcheck.run_test
  16. """
  17. saltcheck_test = {
  18. "module_and_function": "test.echo",
  19. "assertion": "assertEqual",
  20. "expected_return": "This works!",
  21. "args": ["This works!"],
  22. }
  23. ret = self.run_function("saltcheck.run_test", test=saltcheck_test)
  24. self.assertDictContainsSubset({"status": "Pass"}, ret)
  25. @slowTest
  26. def test_saltcheck_state(self):
  27. """
  28. saltcheck.run_state_tests
  29. """
  30. saltcheck_test = "validate-saltcheck"
  31. ret = self.run_function("saltcheck.run_state_tests", [saltcheck_test])
  32. self.assertDictContainsSubset(
  33. {"status": "Pass"}, ret[0]["validate-saltcheck"]["echo_test_hello"]
  34. )
  35. self.assertDictContainsSubset({"Failed": 0}, ret[1]["TEST RESULTS"])
  36. @slowTest
  37. def test_topfile_validation(self):
  38. """
  39. saltcheck.run_highstate_tests
  40. """
  41. expected_top_states = self.run_function("state.show_top").get("base", [])
  42. expected_top_states.append("TEST RESULTS")
  43. ret = self.run_function("saltcheck.run_highstate_tests")
  44. for top_state_dict in ret:
  45. self.assertIn(list(top_state_dict)[0], expected_top_states)
  46. @slowTest
  47. def test_saltcheck_checkall(self):
  48. """
  49. Validate saltcheck.run_state_tests check_all for the default saltenv of base.
  50. validate-saltcheck state hosts a saltcheck-tests directory with 2 .tst files. By running
  51. check_all=True, both files should be found and show passed results.
  52. """
  53. saltcheck_test = "validate-saltcheck"
  54. ret = self.run_function(
  55. "saltcheck.run_state_tests", [saltcheck_test], check_all=True
  56. )
  57. self.assertDictContainsSubset(
  58. {"status": "Pass"}, ret[0]["validate-saltcheck"]["echo_test_hello"]
  59. )
  60. self.assertDictContainsSubset(
  61. {"status": "Pass"}, ret[0]["validate-saltcheck"]["check_all_validate"]
  62. )
  63. @slowTest
  64. def test_saltcheck_checkall_saltenv(self):
  65. """
  66. Validate saltcheck.run_state_tests check_all for the prod saltenv
  67. validate-saltcheck state hosts a saltcheck-tests directory with 2 .tst files. By running
  68. check_all=True, both files should be found and show passed results.
  69. """
  70. saltcheck_test = "validate-saltcheck"
  71. ret = self.run_function(
  72. "saltcheck.run_state_tests",
  73. [saltcheck_test],
  74. saltenv="prod",
  75. check_all=True,
  76. )
  77. self.assertDictContainsSubset(
  78. {"status": "Pass"}, ret[0]["validate-saltcheck"]["echo_test_prod_env"]
  79. )
  80. self.assertDictContainsSubset(
  81. {"status": "Pass"}, ret[0]["validate-saltcheck"]["check_all_validate_prod"]
  82. )