test_saltcheck.py 3.5 KB

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