1
0

test_sysrc.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  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(
  19. ret, dict, "sysrc.get returned wrong type, expecting dictionary"
  20. )
  21. self.assertIn(
  22. "/etc/rc.conf", ret, "sysrc.get should have an rc.conf key in it."
  23. )
  24. @skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
  25. @destructiveTest
  26. def test_set(self):
  27. ret = self.run_function("sysrc.set", ["test_var", "1"])
  28. self.assertIsInstance(
  29. ret, dict, "sysrc.get returned wrong type, expecting dictionary"
  30. )
  31. self.assertIn(
  32. "/etc/rc.conf", ret, "sysrc.set should have an rc.conf key in it."
  33. )
  34. self.assertIn(
  35. "1",
  36. ret["/etc/rc.conf"]["test_var"],
  37. "sysrc.set should return the value it set.",
  38. )
  39. ret = self.run_function("sysrc.remove", ["test_var"])
  40. self.assertEqual("test_var removed", ret)
  41. @skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
  42. @destructiveTest
  43. def test_set_bool(self):
  44. ret = self.run_function("sysrc.set", ["test_var", True])
  45. self.assertIsInstance(
  46. ret, dict, "sysrc.get returned wrong type, expecting dictionary"
  47. )
  48. self.assertIn(
  49. "/etc/rc.conf", ret, "sysrc.set should have an rc.conf key in it."
  50. )
  51. self.assertIn(
  52. "YES",
  53. ret["/etc/rc.conf"]["test_var"],
  54. "sysrc.set should return the value it set.",
  55. )
  56. ret = self.run_function("sysrc.remove", ["test_var"])
  57. self.assertEqual("test_var removed", ret)