test_cron.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the cron state
  4. """
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import logging
  8. import pytest
  9. # Import Salt libs
  10. import salt.utils.platform
  11. # Import Salt Testing libs
  12. from tests.support.case import ModuleCase
  13. from tests.support.unit import skipIf
  14. log = logging.getLogger(__name__)
  15. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  16. class CronTest(ModuleCase):
  17. """
  18. Validate the file state
  19. """
  20. def setUp(self):
  21. """
  22. Setup
  23. """
  24. self.run_state("user.present", name="test_cron_user")
  25. def tearDown(self):
  26. """
  27. Teardown
  28. """
  29. # Remove cron file
  30. self.run_function("cmd.run", cmd="crontab -u test_cron_user -r")
  31. # Delete user
  32. self.run_state("user.absent", name="test_cron_user")
  33. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  34. def test_managed(self):
  35. """
  36. file.managed
  37. """
  38. ret = self.run_state(
  39. "cron.file", name="salt://issue-46881/cron", user="test_cron_user"
  40. )
  41. _expected = "--- \n+++ \n@@ -1 +1,2 @@\n-\n+# Lines below here are managed by Salt, do not edit\n+@hourly touch /tmp/test-file\n"
  42. self.assertIn(
  43. "changes",
  44. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"],
  45. )
  46. self.assertIn(
  47. "diff",
  48. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"][
  49. "changes"
  50. ],
  51. )
  52. self.assertEqual(
  53. _expected,
  54. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"][
  55. "changes"
  56. ]["diff"],
  57. )