test_win_dsc.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import os
  4. import pytest
  5. import salt.utils.files
  6. import salt.utils.platform
  7. from tests.support.case import ModuleCase
  8. from tests.support.runtests import RUNTIME_VARS
  9. from tests.support.unit import skipIf
  10. @skipIf(not salt.utils.platform.is_windows(), "Tests for only Windows")
  11. class DscModuleTest(ModuleCase):
  12. """
  13. Validate PowerShell DSC module
  14. """
  15. def setUp(self):
  16. self.ps1file = os.path.join(RUNTIME_VARS.TMP, "HelloWorld.ps1")
  17. with salt.utils.files.fopen(
  18. os.path.join(RUNTIME_VARS.FILES, "file", "base", "HelloWorld.ps1"), "rb"
  19. ) as sfp:
  20. with salt.utils.files.fopen(self.ps1file, "wb") as dfp:
  21. dfp.write(sfp.read())
  22. self.psd1file = os.path.join(RUNTIME_VARS.TMP, "HelloWorld.psd1")
  23. with salt.utils.files.fopen(
  24. os.path.join(RUNTIME_VARS.FILES, "file", "base", "HelloWorld.psd1"), "rb"
  25. ) as sfp:
  26. with salt.utils.files.fopen(self.psd1file, "wb") as dfp:
  27. dfp.write(sfp.read())
  28. super(DscModuleTest, self).setUp()
  29. def tearDown(self):
  30. if os.path.isfile(self.ps1file):
  31. os.remove(self.ps1file)
  32. if os.path.isfile(self.psd1file):
  33. os.remove(self.psd1file)
  34. super(DscModuleTest, self).tearDown()
  35. @pytest.mark.destructive_test
  36. def test_compile_config(self):
  37. ret = self.run_function(
  38. "dsc.compile_config",
  39. self.ps1file,
  40. config_name="HelloWorld",
  41. config_data=self.psd1file,
  42. )
  43. self.assertTrue(ret["Exists"])