test_win_service.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import salt.utils.platform
  2. from tests.support.unit import TestCase, skipIf
  3. try:
  4. import salt.utils.win_service as win_service
  5. except Exception as exc: # pylint: disable=broad-except
  6. win_service = exc
  7. class WinServiceImportTestCase(TestCase):
  8. def test_import(self):
  9. """
  10. Simply importing should not raise an error, especially on Linux
  11. """
  12. if isinstance(win_service, Exception):
  13. raise Exception(
  14. "Importing win_system caused traceback: {}".format(win_service)
  15. )
  16. @skipIf(not salt.utils.platform.is_windows(), "Only test on Windows systems")
  17. class WinServiceTestCase(TestCase):
  18. """
  19. Test cases for salt.utils.win_service
  20. """
  21. def test_info(self):
  22. """
  23. Test service.info
  24. """
  25. # Get info about the spooler service
  26. info = win_service.info("spooler")
  27. # Make sure it returns these fields
  28. field_names = [
  29. "BinaryPath",
  30. "ControlsAccepted",
  31. "Dependencies",
  32. "Description",
  33. "DisplayName",
  34. "ErrorControl",
  35. "LoadOrderGroup",
  36. "ServiceAccount",
  37. "ServiceType",
  38. "StartType",
  39. "StartTypeDelayed",
  40. "Status",
  41. "Status_CheckPoint",
  42. "Status_ExitCode",
  43. "Status_ServiceCode",
  44. "Status_WaitHint",
  45. "TagID",
  46. "sid",
  47. ]
  48. for field_name in field_names:
  49. self.assertIn(field_name, info)
  50. # Make sure it returns a valid Display Name
  51. self.assertEqual(info["DisplayName"], "Print Spooler")