test_sysrc.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, unicode_literals, print_function
  4. import sys
  5. # Import Salt Testing libs
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import destructiveTest
  8. from tests.support.unit import skipIf
  9. class SysrcModuleTest(ModuleCase):
  10. def setUp(self):
  11. super(SysrcModuleTest, self).setUp()
  12. ret = self.run_function('cmd.has_exec', ['sysrc'])
  13. if not ret:
  14. self.skipTest('sysrc not found')
  15. @skipIf(not sys.platform.startswith('freebsd'), 'FreeBSD specific')
  16. def test_show(self):
  17. ret = self.run_function('sysrc.get')
  18. self.assertIsInstance(ret, dict, 'sysrc.get returned wrong type, expecting dictionary')
  19. self.assertIn('/etc/rc.conf', ret, 'sysrc.get should have an rc.conf key in it.')
  20. @skipIf(not sys.platform.startswith('freebsd'), 'FreeBSD specific')
  21. @destructiveTest
  22. def test_set(self):
  23. ret = self.run_function('sysrc.set', ['test_var', '1'])
  24. self.assertIsInstance(ret, dict, 'sysrc.get returned wrong type, expecting dictionary')
  25. self.assertIn('/etc/rc.conf', ret, 'sysrc.set should have an rc.conf key in it.')
  26. self.assertIn('1', ret['/etc/rc.conf']['test_var'], 'sysrc.set should return the value it set.')
  27. ret = self.run_function('sysrc.remove', ['test_var'])
  28. self.assertEqual('test_var removed', ret)
  29. @skipIf(not sys.platform.startswith('freebsd'), 'FreeBSD specific')
  30. @destructiveTest
  31. def test_set_bool(self):
  32. ret = self.run_function('sysrc.set', ['test_var', True])
  33. self.assertIsInstance(ret, dict, 'sysrc.get returned wrong type, expecting dictionary')
  34. self.assertIn('/etc/rc.conf', ret, 'sysrc.set should have an rc.conf key in it.')
  35. self.assertIn('YES', ret['/etc/rc.conf']['test_var'], 'sysrc.set should return the value it set.')
  36. ret = self.run_function('sysrc.remove', ['test_var'])
  37. self.assertEqual('test_var removed', ret)