summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-09-25 16:08:59 -0400
committerBryan McLellan <btm@loftninjas.org>2014-09-30 20:13:29 -0400
commit4c544937dbb80fe2e74ccd4054ee328569aad6b3 (patch)
treec1813cf38eeccb43aa30d195ae13a621709d617b
parenteb82af0476f627b1107f272544109d7b847490ad (diff)
downloadchef-4c544937dbb80fe2e74ccd4054ee328569aad6b3.tar.gz
nest powershell guard functional tests
reorder the powershell functional tests to provide a framework for testing with guard_interpreter set and not set (allowing testing the "default", i.e. values on resource initialization).
-rw-r--r--spec/functional/resource/powershell_spec.rb331
1 files changed, 176 insertions, 155 deletions
diff --git a/spec/functional/resource/powershell_spec.rb b/spec/functional/resource/powershell_spec.rb
index c30c710959..06470a27d4 100644
--- a/spec/functional/resource/powershell_spec.rb
+++ b/spec/functional/resource/powershell_spec.rb
@@ -210,217 +210,238 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
describe "when executing guards" do
-
before(:each) do
resource.not_if.clear
resource.only_if.clear
- resource.guard_interpreter :powershell_script
+ # resource.guard_interpreter should be :default by default
end
it "evaluates a succeeding not_if block using cmd.exe as false by default" do
- resource.guard_interpreter :default
resource.not_if "exit /b 0"
resource.should_skip?(:run).should be_true
end
it "evaluates a failing not_if block using cmd.exe as true by default" do
- resource.guard_interpreter :default
resource.not_if "exit /b 2"
resource.should_skip?(:run).should be_false
end
it "evaluates an succeeding only_if block using cmd.exe as true by default" do
- resource.guard_interpreter :default
resource.only_if "exit /b 0"
resource.should_skip?(:run).should be_false
end
it "evaluates a failing only_if block using cmd.exe as false by default" do
- resource.guard_interpreter :default
resource.only_if "exit /b 2"
resource.should_skip?(:run).should be_true
end
- it "evaluates a powershell $false for a not_if block as true" do
- resource.not_if "$false"
- resource.should_skip?(:run).should be_false
- end
+ context "with powershell_script as the guard_interpreter" do
+ before(:each) do
+ resource.guard_interpreter :powershell_script
+ end
- it "evaluates a powershell $true for a not_if block as false" do
- resource.not_if "$true"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a powershell $false for a not_if block as true" do
+ resource.not_if "$false"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a powershell $false for an only_if block as false" do
- resource.only_if "$false"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a powershell $true for a not_if block as false" do
+ resource.not_if "$true"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a powershell $true for a only_if block as true" do
- resource.only_if "$true"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a powershell $false for an only_if block as false" do
+ resource.only_if "$false"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a not_if block using powershell.exe" do
- resource.not_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a powershell $true for a only_if block as true" do
+ resource.only_if "$true"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates an only_if block using powershell.exe" do
- resource.only_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a not_if block using powershell.exe" do
+ resource.not_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a non-zero powershell exit status for not_if as true" do
- resource.not_if "exit 37"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates an only_if block using powershell.exe" do
+ resource.only_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a zero powershell exit status for not_if as false" do
- resource.not_if "exit 0"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a not_if block as false" do
+ resource.not_if { false }
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a failed executable exit status for not_if as false" do
- resource.not_if windows_process_exit_code_not_found_content
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a not_if block as true" do
+ resource.not_if { true }
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a successful executable exit status for not_if as true" do
- resource.not_if windows_process_exit_code_success_content
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates an only_if block as false" do
+ resource.only_if { false }
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a failed executable exit status for only_if as false" do
- resource.only_if windows_process_exit_code_not_found_content
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates an only_if block as true" do
+ resource.only_if { true }
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a successful executable exit status for only_if as true" do
- resource.only_if windows_process_exit_code_success_content
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a non-zero powershell exit status for not_if as true" do
+ resource.not_if "exit 37"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a failed cmdlet exit status for not_if as true" do
- resource.not_if "throw 'up'"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a zero powershell exit status for not_if as false" do
+ resource.not_if "exit 0"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a successful cmdlet exit status for not_if as true" do
- resource.not_if "cd ."
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a failed executable exit status for not_if as false" do
+ resource.not_if windows_process_exit_code_not_found_content
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a failed cmdlet exit status for only_if as false" do
- resource.only_if "throw 'up'"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a successful executable exit status for not_if as true" do
+ resource.not_if windows_process_exit_code_success_content
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a successful cmdlet exit status for only_if as true" do
- resource.only_if "cd ."
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a failed executable exit status for only_if as false" do
+ resource.only_if windows_process_exit_code_not_found_content
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a not_if block using the cwd guard parameter" do
- custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
- resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a successful executable exit status for only_if as true" do
+ resource.only_if windows_process_exit_code_success_content
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates an only_if block using the cwd guard parameter" do
- custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
- resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a failed cmdlet exit status for not_if as true" do
+ resource.not_if "throw 'up'"
+ resource.should_skip?(:run).should be_false
+ end
- it "inherits cwd from the parent resource for only_if" do
- custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
- resource.cwd custom_cwd
- resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a successful cmdlet exit status for not_if as true" do
+ resource.not_if "cd ."
+ resource.should_skip?(:run).should be_true
+ end
- it "inherits cwd from the parent resource for not_if" do
- custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
- resource.cwd custom_cwd
- resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a failed cmdlet exit status for only_if as false" do
+ resource.only_if "throw 'up'"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean false as zero status code", :windows64_only do
- resource.architecture :x86_64
- resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'AMD64')"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a successful cmdlet exit status for only_if as true" do
+ resource.only_if "cd ."
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do
- resource.architecture :x86_64
- resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a not_if block using the cwd guard parameter" do
+ custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
+ resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do
- resource.architecture :i386
- resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates an only_if block using the cwd guard parameter" do
+ custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
+ resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do
- resource.architecture :i386
- resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')"
- resource.should_skip?(:run).should be_true
- end
+ it "inherits cwd from the parent resource for only_if" do
+ custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
+ resource.cwd custom_cwd
+ resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do
- resource.convert_boolean_return true
- resource.only_if "$false"
- resource.should_skip?(:run).should be_true
- end
+ it "inherits cwd from the parent resource for not_if" do
+ custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
+ resource.cwd custom_cwd
+ resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do
- resource.convert_boolean_return true
- resource.not_if "$false"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean false as zero status code", :windows64_only do
+ resource.architecture :x86_64
+ resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'AMD64')"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for only_if" do
- resource.convert_boolean_return true
- resource.only_if "$true"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do
+ resource.architecture :x86_64
+ resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for not_if" do
- resource.convert_boolean_return true
- resource.not_if "$true"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do
+ resource.architecture :i386
+ resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do
- resource.convert_boolean_return true
- resource.architecture :i386
- resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do
+ resource.architecture :i386
+ resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do
- resource.convert_boolean_return true
- resource.architecture :i386
- resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
- resource.should_skip?(:run).should be_false
- end
+ it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do
+ resource.convert_boolean_return true
+ resource.only_if "$false"
+ resource.should_skip?(:run).should be_true
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do
- resource.convert_boolean_return true
- resource.architecture :i386
- resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
- resource.should_skip?(:run).should be_true
- end
+ it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do
+ resource.convert_boolean_return true
+ resource.not_if "$false"
+ resource.should_skip?(:run).should be_false
+ end
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do
- resource.convert_boolean_return true
- resource.architecture :i386
- resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
- resource.should_skip?(:run).should be_true
+ it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for only_if" do
+ resource.convert_boolean_return true
+ resource.only_if "$true"
+ resource.should_skip?(:run).should be_false
+ end
+
+ it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for not_if" do
+ resource.convert_boolean_return true
+ resource.not_if "$true"
+ resource.should_skip?(:run).should be_true
+ end
+
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do
+ resource.convert_boolean_return true
+ resource.architecture :i386
+ resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
+ resource.should_skip?(:run).should be_false
+ end
+
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do
+ resource.convert_boolean_return true
+ resource.architecture :i386
+ resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
+ resource.should_skip?(:run).should be_false
+ end
+
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do
+ resource.convert_boolean_return true
+ resource.architecture :i386
+ resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
+ resource.should_skip?(:run).should be_true
+ end
+
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do
+ resource.convert_boolean_return true
+ resource.architecture :i386
+ resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
+ resource.should_skip?(:run).should be_true
+ end
end
end