puppetlabs / ruby-pwsh

A ruby gem for interacting with PowerShell
MIT License
15 stars 21 forks source link

Support unit testing DSC resources on Unix OS distributions by enabling option of powershell or pwsh within the dsc_base_provider #308

Closed chambersmp closed 2 months ago

chambersmp commented 3 months ago

Use Case

Unix OS should be able to run unit tests for DSC resources

Currently unit tests for DSC resources must be performed on a Windows host as there is a dependency on PowerShell to execute the canonicalize provider method during catalog compilation.

This often requires a complex Vagrant, Terraform, Build setup to provision short-term Windows VMs for ephemeral unit testing. This is a potentially complex and costly setup for users.

Issue Background

The canonicalize method triggers a PowerShell process on agent or test hardware during catalog compilation to Get current state of DSC resources on the target node. The feature is implemented to negate unnecessary corrective actions due to case-mismatch. The provider is currently limited to PowerShell (Windows only). See ref: https://www.puppet.com/docs/puppet/8/about_the_resource_api.html#provider_features-canonicalize

Describe the Solution You Would Like

  1. The Unix OS running as test hardware will require pwsh to be installed and the $PSPATH added to $PATH.

  2. The dsc_base_provider should utilise pwsh in the ps_manager method to ensure Unix platforms successfully execute the canonicalise method to normalise User data values supplied within the manifest.

  3. The 'Pwsh::Manager.pwsh_path' method should consistently split the $PATH system variable by ':' when the ruby interpreter is run on Unix OS.

  4. Pwsh::Util.on_windows? method should identify the OS running the Ruby interpreter not the synthetic context OS within rspec to ensure Unix conditional code is respected.