1
0

test_cron.py 1.7 KB

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