test_cron.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. log = logging.getLogger(__name__)
  9. # Import Salt Testing libs
  10. from tests.support.case import ModuleCase
  11. from tests.support.unit import skipIf
  12. # Import Salt libs
  13. import salt.utils.platform
  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',
  30. cmd='crontab -u test_cron_user -r')
  31. # Delete user
  32. self.run_state('user.absent', name='test_cron_user')
  33. def test_managed(self):
  34. '''
  35. file.managed
  36. '''
  37. ret = self.run_state(
  38. 'cron.file',
  39. name='salt://issue-46881/cron',
  40. user='test_cron_user'
  41. )
  42. _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'
  43. self.assertIn('changes', ret['cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file'])
  44. self.assertIn('diff', ret['cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file']['changes'])
  45. self.assertEqual(_expected, ret['cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file']['changes']['diff'])