test_cron.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. Tests for the cron state
  3. """
  4. import logging
  5. import salt.utils.platform
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import slowTest
  8. from tests.support.unit import skipIf
  9. log = logging.getLogger(__name__)
  10. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  11. class CronTest(ModuleCase):
  12. """
  13. Validate the file state
  14. """
  15. def setUp(self):
  16. """
  17. Setup
  18. """
  19. self.run_state("user.present", name="test_cron_user")
  20. def tearDown(self):
  21. """
  22. Teardown
  23. """
  24. # Remove cron file
  25. if salt.utils.platform.is_freebsd():
  26. self.run_function("cmd.run", cmd="crontab -u test_cron_user -rf")
  27. else:
  28. self.run_function("cmd.run", cmd="crontab -u test_cron_user -r")
  29. # Delete user
  30. self.run_state("user.absent", name="test_cron_user")
  31. @slowTest
  32. def test_managed(self):
  33. """
  34. file.managed
  35. """
  36. ret = self.run_state(
  37. "cron.file", name="salt://issue-46881/cron", user="test_cron_user"
  38. )
  39. _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"
  40. self.assertIn(
  41. "changes",
  42. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"],
  43. )
  44. self.assertIn(
  45. "diff",
  46. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"][
  47. "changes"
  48. ],
  49. )
  50. self.assertEqual(
  51. _expected,
  52. ret["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"][
  53. "changes"
  54. ]["diff"],
  55. )