test_cron.py 1.7 KB

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