12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # -*- coding: utf-8 -*-
- # Import python libs
- from __future__ import absolute_import, print_function, unicode_literals
- import sys
- import pytest
- # Import Salt Testing libs
- from tests.support.case import ModuleCase
- from tests.support.unit import skipIf
- class SysctlModuleTest(ModuleCase):
- def setUp(self):
- super(SysctlModuleTest, self).setUp()
- ret = self.run_function("cmd.has_exec", ["sysctl"])
- if not ret:
- self.skipTest("sysctl not found")
- @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
- def test_show(self):
- ret = self.run_function("sysctl.show")
- self.assertIsInstance(ret, dict, "sysctl.show return wrong type")
- self.assertGreater(len(ret), 10, "sysctl.show return few data")
- @skipIf(not sys.platform.startswith("linux"), "Linux specific")
- @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
- def test_show_linux(self):
- ret = self.run_function("sysctl.show")
- self.assertIn("kernel.ostype", ret, "kernel.ostype absent")
- @skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
- def test_show_freebsd(self):
- ret = self.run_function("sysctl.show")
- self.assertIn("vm.vmtotal", ret, "Multiline variable absent")
- self.assertGreater(
- len(ret.get("vm.vmtotal").splitlines()),
- 1,
- "Multiline value was parsed wrong",
- )
- @skipIf(not sys.platform.startswith("openbsd"), "OpenBSD specific")
- def test_show_openbsd(self):
- ret = self.run_function("sysctl.show")
- self.assertIn("kern.ostype", ret, "kern.ostype absent")
- self.assertEqual(ret.get("kern.ostype"), "OpenBSD", "Incorrect kern.ostype")
- @skipIf(not sys.platform.startswith("darwin"), "Darwin (macOS) specific")
- @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
- def test_show_darwin(self):
- ret = self.run_function("sysctl.show")
- self.assertIn("kern.ostype", ret, "kern.ostype absent")
- self.assertEqual(ret.get("kern.ostype"), "Darwin", "Incorrect kern.ostype")
|