test_sysrc.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, unicode_literals, print_function
  4. import sys
  5. import pytest
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  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. @pytest.mark.destructive_test
  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. @pytest.mark.destructive_test
  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)