1
0

test_saltcheck.py 3.4 KB

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