summaryrefslogtreecommitdiff
path: root/spec/functional/resource/powershell_script_spec.rb
diff options
context:
space:
mode:
authormwrock <matt@mattwrock.com>2020-10-07 11:02:54 -0700
committermwrock <matt@mattwrock.com>2020-10-07 11:02:54 -0700
commit03f70aede103ffdea053affff3231c2b07fcebe9 (patch)
tree8c47753057f9aa81ef1da0e68f2f10b14b3b9341 /spec/functional/resource/powershell_script_spec.rb
parent0e268d038575d781ff396ce6307a20834ef52cae (diff)
downloadchef-ps_script.tar.gz
add interpreter to handle pwsh and powershell to powershell_scriptps_script
Signed-off-by: mwrock <matt@mattwrock.com>
Diffstat (limited to 'spec/functional/resource/powershell_script_spec.rb')
-rw-r--r--spec/functional/resource/powershell_script_spec.rb71
1 files changed, 57 insertions, 14 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb
index 70442eb2b1..68fa94afe9 100644
--- a/spec/functional/resource/powershell_script_spec.rb
+++ b/spec/functional/resource/powershell_script_spec.rb
@@ -47,7 +47,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
r
end
- describe "when the run action is invoked on Windows" do
+ shared_examples_for "a running powershell script" do
it "successfully executes a non-cmdlet Windows binary as the last command of the script" do
resource.code(successful_executable_script_content + " | out-file -encoding ASCII #{script_output_path}")
resource.returns(0)
@@ -231,22 +231,54 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
resource.only_if { true }
expect { resource.should_skip?(:run) }.to raise_error(ArgumentError, /guard_interpreter does not support blocks/)
end
+ end
+
+ context "when using the powershell interpreter" do
+ before do
+ resource.interpreter "powershell"
+ end
+
+ it_behaves_like "a running powershell script"
+
+ it "runs Windows Powershell" do
+ resource.code("$PSVersionTable.PSVersion.Major | out-file -encoding ASCII #{script_output_path}")
+ resource.returns(0)
+ resource.run_action(:run)
+
+ expect(get_script_output.to_i).to be < 6
+ end
+ end
+
+ context "when using the pwsh interpreter", :pwsh_installed do
+ before do
+ resource.interpreter "pwsh"
+ end
+
+ it_behaves_like "a running powershell script"
- context "when dsc is supported", :windows_powershell_dsc_only do
- it "can execute LCM configuration code" do
- resource.code <<~EOF
- configuration LCM
+ it "runs a version of powershell greater than 6" do
+ resource.code("$PSVersionTable.PSVersion.Major | out-file -encoding ASCII #{script_output_path}")
+ resource.returns(0)
+ resource.run_action(:run)
+
+ expect(get_script_output.to_i).to be > 6
+ end
+ end
+
+ context "when dsc is supported", :windows_powershell_dsc_only do
+ it "can execute LCM configuration code" do
+ resource.code <<~EOF
+ configuration LCM
+ {
+ param ($thumbprint)
+ localconfigurationmanager
{
- param ($thumbprint)
- localconfigurationmanager
- {
- RebootNodeIfNeeded = $false
- ConfigurationMode = 'ApplyOnly'
- }
+ RebootNodeIfNeeded = $false
+ ConfigurationMode = 'ApplyOnly'
}
- EOF
- expect { resource.run_action(:run) }.not_to raise_error
- end
+ }
+ EOF
+ expect { resource.run_action(:run) }.not_to raise_error
end
end
@@ -347,6 +379,17 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
context "with powershell_script as the guard_interpreter" do
+ context "when pwsh is the interpreter", :pwsh_installed do
+ before do
+ resource.interpreter "pwsh"
+ end
+
+ it "uses powershell core to evaluate the guard" do
+ resource.not_if "$PSVersionTable.PSEdition -eq 'Core'"
+ expect(resource.should_skip?(:run)).to be_truthy
+ end
+ end
+
it "has a guard_interpreter attribute set to :powershell_script" do
expect(resource.guard_interpreter).to eq(:powershell_script)
end