summaryrefslogtreecommitdiff
path: root/spec/functional
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functional')
-rw-r--r--spec/functional/dsl/reboot_pending_spec.rb118
-rw-r--r--spec/functional/resource/base.rb4
-rw-r--r--spec/functional/resource/deploy_revision_spec.rb193
-rw-r--r--spec/functional/resource/git_spec.rb2
-rw-r--r--spec/functional/resource/ohai_spec.rb65
-rw-r--r--spec/functional/resource/powershell_spec.rb263
-rw-r--r--spec/functional/resource/registry_spec.rb9
-rw-r--r--spec/functional/win32/versions_spec.rb6
8 files changed, 646 insertions, 14 deletions
diff --git a/spec/functional/dsl/reboot_pending_spec.rb b/spec/functional/dsl/reboot_pending_spec.rb
new file mode 100644
index 0000000000..10d667f7bd
--- /dev/null
+++ b/spec/functional/dsl/reboot_pending_spec.rb
@@ -0,0 +1,118 @@
+#
+# Author:: Bryan McLellan <btm@loftninjas.org>
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "chef/dsl/reboot_pending"
+require "chef/win32/registry"
+require "spec_helper"
+
+describe Chef::DSL::RebootPending, :windows_only do
+ def run_ohai
+ ohai = Ohai::System.new
+ # Would be nice to limit this to platform/kernel/arch etc for Ohai 7
+ ohai.all_plugins
+ node.consume_external_attrs(ohai.data,{})
+
+ ohai
+ end
+
+ def registry_safe?
+ !registry.value_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { :name => 'PendingFileRenameOperations' }) ||
+ !registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') ||
+ !registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired') ||
+ !registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile')
+ end
+
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let!(:ohai) { run_ohai } # Ensure we have necessary node data
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:recipe) { Chef::Recipe.new("a windows cookbook", "the windows recipe", run_context) }
+ let(:registry) { Chef::Win32::Registry.new(run_context) }
+
+ describe "reboot_pending?" do
+
+ context "when there is nothing to indicate a reboot is pending" do
+ it { expect(recipe.reboot_pending?).to be_false }
+ end
+
+ describe 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations' do
+ it "returns true if the registry value exists" do
+ pending "Found existing registry keys" unless registry_safe?
+ registry.set_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager',
+ { :name => 'PendingFileRenameOperations', :type => :multi_string, :data => ['\??\C:\foo.txt|\??\C:\bar.txt'] })
+
+ expect(recipe.reboot_pending?).to be_true
+ end
+
+ after do
+ if registry_safe?
+ registry.delete_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { :name => 'PendingFileRenameOperations' })
+ end
+ end
+ end
+
+ describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' do
+ it "returns true if the registry key exists" do
+ pending "Found existing registry keys" unless registry_safe?
+ registry.create_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired', false)
+
+ expect(recipe.reboot_pending?).to be_true
+ end
+
+ after do
+ if registry_safe?
+ registry.delete_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired', false)
+ end
+ end
+ end
+
+ describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired' do
+ it "returns true if the registry key exists" do
+ pending "Permissions are limited to 'TrustedInstaller' by default"
+ pending "Found existing registry keys" unless registry_safe?
+ registry.create_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired', false)
+
+ expect(recipe.reboot_pending?).to be_true
+ end
+
+ after do
+ if registry_safe?
+ registry.delete_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired', false)
+ end
+ end
+ end
+
+ describe 'HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile\Flags' do
+ it "returns true if the registry key exists" do
+ pending "Found existing registry keys" unless registry_safe?
+ registry.create_key('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', true)
+ registry.set_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile',
+ { :name => 'Flags', :type => :dword, :data => 3 })
+
+ expect(recipe.reboot_pending?).to be_true
+ end
+
+ after do
+ if registry_safe?
+ registry.delete_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', { :name => 'Flags' })
+ registry.delete_key('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', false)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/functional/resource/base.rb b/spec/functional/resource/base.rb
index 13438c1759..056db39877 100644
--- a/spec/functional/resource/base.rb
+++ b/spec/functional/resource/base.rb
@@ -22,9 +22,7 @@ def ohai
# provider is platform-dependent, we need platform ohai data:
@OHAI_SYSTEM ||= begin
ohai = Ohai::System.new
- ohai.require_plugin("os")
- ohai.require_plugin("platform")
- ohai.require_plugin("passwd")
+ ohai.all_plugins("platform")
ohai
end
end
diff --git a/spec/functional/resource/deploy_revision_spec.rb b/spec/functional/resource/deploy_revision_spec.rb
index 14e6e69d6d..9ff1391e35 100644
--- a/spec/functional/resource/deploy_revision_spec.rb
+++ b/spec/functional/resource/deploy_revision_spec.rb
@@ -45,7 +45,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
before(:all) do
@ohai = Ohai::System.new
- @ohai.require_plugin("os")
+ @ohai.all_plugins("os")
end
let(:node) do
@@ -78,6 +78,9 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
# This is the third version
let(:previous_rev) { "6d19a6dbecc8e37f5b2277345885c0c783eb8fb1" }
+ # This is the second version
+ let(:second_rev) { "0827e1b0e5043608ac0a824da5c558e252154ad0" }
+
# This is the sixth version, it is on the "with-deploy-scripts" branch
let(:rev_with_in_repo_callbacks) { "2404d015882659754bdb93ad6e4b4d3d02691a82" }
@@ -100,6 +103,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
let(:basic_deploy_resource) do
Chef::Resource::DeployRevision.new(deploy_directory, run_context).tap do |r|
+ r.name "deploy-revision-unit-test"
r.repo git_bundle_repo
r.symlink_before_migrate({})
r.symlinks({})
@@ -127,6 +131,34 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
end
end
+ let(:deploy_to_previous_rev_again) do
+ basic_deploy_resource.dup.tap do |r|
+ r.revision(previous_rev)
+ r.restart_command shell_restart_command(:deploy_to_previous_rev_again)
+ end
+ end
+
+ let(:deploy_to_second_rev) do
+ basic_deploy_resource.dup.tap do |r|
+ r.revision(second_rev)
+ r.restart_command shell_restart_command(:deploy_to_second_rev)
+ end
+ end
+
+ let(:deploy_to_second_rev_again) do
+ basic_deploy_resource.dup.tap do |r|
+ r.revision(second_rev)
+ r.restart_command shell_restart_command(:deploy_to_second_rev_again)
+ end
+ end
+
+ let(:deploy_to_second_rev_again_again) do
+ basic_deploy_resource.dup.tap do |r|
+ r.revision(second_rev)
+ r.restart_command shell_restart_command(:deploy_to_second_rev_again_again)
+ end
+ end
+
# Computes the full path for +path+ relative to the deploy directory
def rel_path(path)
File.expand_path(path, deploy_directory)
@@ -306,6 +338,165 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
end
end
+ describe "back to a previously deployed revision where resource rev == latest revision (explicit rollback)" do
+ before do
+ deploy_to_previous_rev.run_action(:deploy)
+ @previous_rev_all_releases = deploy_to_previous_rev.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev.run_action(:deploy)
+ @latest_rev_all_releases = deploy_to_latest_rev.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev_again.run_action(:rollback)
+ @previous_rev_again_all_releases = deploy_to_latest_rev_again.provider_for_action(:deploy).all_releases
+ end
+
+ the_app_is_deployed_at_revision(:previous_rev)
+
+ it "restarts the application after rolling back" do
+ actual_operations_order.should == %w[deploy_to_previous_rev deploy_to_latest_rev deploy_to_latest_rev_again]
+ end
+
+ it "is marked updated" do
+ deploy_to_latest_rev_again.should be_updated_by_last_action
+ end
+
+ it "deploys the right code" do
+ IO.read(rel_path("current/app/app.rb")).should include("this is the third version of the app")
+ end
+
+ it "all_releases after first deploy should have one entry" do
+ @previous_rev_all_releases.length.should == 1
+ end
+
+ it "all_releases after second deploy should have two entries" do
+ @latest_rev_all_releases.length.should == 2
+ end
+
+ it "all_releases after rollback should have one entry" do
+ @previous_rev_again_all_releases.length.should == 1
+ end
+
+ it "all_releases after rollback should be the same as after the first deploy" do
+ @previous_rev_again_all_releases.should == @previous_rev_all_releases
+ end
+
+ end
+
+ describe "back to a previously deployed revision where resource rev == previous revision (explicit rollback)" do
+ before do
+ deploy_to_previous_rev.run_action(:deploy)
+ @previous_rev_all_releases = deploy_to_previous_rev.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev.run_action(:deploy)
+ @latest_rev_all_releases = deploy_to_latest_rev.provider_for_action(:deploy).all_releases
+ deploy_to_previous_rev_again.run_action(:rollback)
+ # FIXME: only difference with previous test is using latest_rev_again insetad of previous_rev_again
+ @previous_rev_again_all_releases = deploy_to_latest_rev_again.provider_for_action(:deploy).all_releases
+ end
+
+ the_app_is_deployed_at_revision(:previous_rev)
+
+ it "restarts the application after rolling back" do
+ actual_operations_order.should == %w[deploy_to_previous_rev deploy_to_latest_rev deploy_to_previous_rev_again]
+ end
+
+ it "is marked updated" do
+ deploy_to_previous_rev_again.should be_updated_by_last_action
+ end
+
+ it "deploys the right code" do
+ IO.read(rel_path("current/app/app.rb")).should include("this is the third version of the app")
+ end
+
+ it "all_releases after first deploy should have one entry" do
+ @previous_rev_all_releases.length.should == 1
+ end
+
+ it "all_releases after second deploy should have two entries" do
+ @latest_rev_all_releases.length.should == 2
+ end
+
+ it "all_releases after rollback should have one entry" do
+ @previous_rev_again_all_releases.length.should == 1
+ end
+
+ it "all_releases after rollback should be the same as after the first deploy" do
+ @previous_rev_again_all_releases.should == @previous_rev_all_releases
+ end
+ end
+
+ describe "back to a previously deployed revision where resource rev == latest revision (explicit rollback)" do
+ before do
+ deploy_to_second_rev.run_action(:deploy)
+ @first_deploy_all_releases = deploy_to_second_rev.provider_for_action(:deploy).all_releases
+ deploy_to_previous_rev.run_action(:deploy)
+ @second_deploy_all_releases = deploy_to_previous_rev.provider_for_action(:deploy).all_releases
+ deploy_to_previous_rev_again.run_action(:rollback)
+ @third_deploy_all_releases = deploy_to_previous_rev_again.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev.run_action(:deploy)
+ @fourth_deploy_all_releases = deploy_to_latest_rev.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev_again.run_action(:rollback)
+ @fifth_deploy_all_releases = deploy_to_latest_rev_again.provider_for_action(:deploy).all_releases
+ end
+
+ the_app_is_deployed_at_revision(:second_rev)
+
+ it "restarts the application after rolling back" do
+ actual_operations_order.should == %w[deploy_to_second_rev deploy_to_previous_rev deploy_to_previous_rev_again deploy_to_latest_rev deploy_to_latest_rev_again]
+ end
+
+ it "is marked updated" do
+ deploy_to_latest_rev_again.should be_updated_by_last_action
+ end
+
+ it "deploys the right code" do
+ IO.read(rel_path("current/app/app.rb")).should include("this is the second version of the app")
+ end
+
+ it "all_releases after rollback should have one entry" do
+ @fifth_deploy_all_releases.length.should == 1
+ end
+
+ it "all_releases after rollback should be the same as after the first deploy" do
+ @fifth_deploy_all_releases.should == @first_deploy_all_releases
+ end
+ end
+
+ describe "back to a previously deployed revision where resource rev == latest revision (explicit rollback)" do
+ before do
+ deploy_to_second_rev.run_action(:deploy)
+ @first_deploy_all_releases = deploy_to_second_rev.provider_for_action(:deploy).all_releases
+ deploy_to_previous_rev.run_action(:deploy)
+ @second_deploy_all_releases = deploy_to_previous_rev.provider_for_action(:deploy).all_releases
+ deploy_to_second_rev_again.run_action(:rollback)
+ @third_deploy_all_releases = deploy_to_second_rev_again.provider_for_action(:deploy).all_releases
+ deploy_to_latest_rev.run_action(:deploy)
+ @fourth_deploy_all_releases = deploy_to_latest_rev.provider_for_action(:deploy).all_releases
+ deploy_to_second_rev_again_again.run_action(:rollback)
+ @fifth_deploy_all_releases = deploy_to_second_rev_again_again.provider_for_action(:deploy).all_releases
+ end
+
+ the_app_is_deployed_at_revision(:second_rev)
+
+ it "restarts the application after rolling back" do
+ actual_operations_order.should == %w[deploy_to_second_rev deploy_to_previous_rev deploy_to_second_rev_again deploy_to_latest_rev deploy_to_second_rev_again_again]
+ end
+
+ it "is marked updated" do
+ deploy_to_second_rev_again_again.should be_updated_by_last_action
+ end
+
+ it "deploys the right code" do
+ IO.read(rel_path("current/app/app.rb")).should include("this is the second version of the app")
+ end
+
+ it "all_releases after rollback should have one entry" do
+ @fifth_deploy_all_releases.length.should == 1
+ end
+
+ it "all_releases after rollback should be the same as after the first deploy" do
+ @fifth_deploy_all_releases.should == @first_deploy_all_releases
+ end
+
+ end
+
# CHEF-3435
describe "to a deploy_to path that does not yet exist" do
diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb
index 7ade6eea21..f0bd94b0c0 100644
--- a/spec/functional/resource/git_spec.rb
+++ b/spec/functional/resource/git_spec.rb
@@ -92,7 +92,7 @@ E
before(:all) do
@ohai = Ohai::System.new
- @ohai.require_plugin("os")
+ @ohai.all_plugins("os")
end
context "working with pathes with special characters" do
diff --git a/spec/functional/resource/ohai_spec.rb b/spec/functional/resource/ohai_spec.rb
new file mode 100644
index 0000000000..b1e4891293
--- /dev/null
+++ b/spec/functional/resource/ohai_spec.rb
@@ -0,0 +1,65 @@
+#
+# Author:: Serdar Sutay (<serdar@opscode.com>)
+# Copyright:: Copyright (c) 2014 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Resource::Ohai do
+ let(:ohai) {
+ o = Ohai::System.new
+ o.all_plugins
+ o
+ }
+
+ let(:node) { Chef::Node.new }
+
+ let(:run_context) {
+ node.default[:platform] = ohai[:platform]
+ node.default[:platform_version] = ohai[:platform_version]
+ events = Chef::EventDispatch::Dispatcher.new
+ Chef::RunContext.new(node, {}, events)
+ }
+
+ shared_examples_for "reloaded :uptime" do
+ it "should reload :uptime" do
+ initial_uptime = ohai[:uptime]
+
+ # Sleep for a second so the uptime gets updated.
+ sleep 1
+
+ ohai_resource.run_action(:reload)
+ node[:uptime].should_not == initial_uptime
+ end
+ end
+
+ describe "when reloading all plugins" do
+ let(:ohai_resource) { Chef::Resource::Ohai.new("reload all", run_context)}
+
+ it_behaves_like "reloaded :uptime"
+ end
+
+ describe "when reloading only uptime" do
+ let(:ohai_resource) {
+ r = Chef::Resource::Ohai.new("reload all", run_context)
+ r.plugin("uptime")
+ r
+ }
+
+
+ it_behaves_like "reloaded :uptime"
+ end
+end
diff --git a/spec/functional/resource/powershell_spec.rb b/spec/functional/resource/powershell_spec.rb
index 6bd3b3c1e5..5001e870a9 100644
--- a/spec/functional/resource/powershell_spec.rb
+++ b/spec/functional/resource/powershell_spec.rb
@@ -84,7 +84,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
# last line executed -- in this case, we return the status of the
# second to last line. This happens because Powershell gives no
# way for us to determine whether the last operation was a cmdlet
- # or Windows process. Because the latter gives more specified
+ # or Windows process. Because the latter gives more specific
# errors than 0 or 1, we return that instead, which is acceptable
# since callers can test for nonzero rather than testing for 1.
it "returns 1 if the last command was a cmdlet that failed and was preceded by an unsuccessfully executed non-cmdlet Windows binary" do
@@ -111,6 +111,32 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
resource.run_action(:run)
end
+ it "returns 0 for $false as the last line of the script when convert_boolean_return is false" do
+ resource.code "$false"
+ resource.returns(0)
+ resource.run_action(:run)
+ end
+
+ it "returns 0 for $true as the last line of the script when convert_boolean_return is false" do
+ resource.code "$true"
+ resource.returns(0)
+ resource.run_action(:run)
+ end
+
+ it "returns 1 for $false as the last line of the script when convert_boolean_return is true" do
+ resource.convert_boolean_return true
+ resource.code "$false"
+ resource.returns(1)
+ resource.run_action(:run)
+ end
+
+ it "returns 0 for $true as the last line of the script when convert_boolean_return is true" do
+ resource.convert_boolean_return true
+ resource.code "$true"
+ resource.returns(0)
+ resource.run_action(:run)
+ end
+
it "executes a script with a 64-bit process on a 64-bit OS, otherwise a 32-bit process" do
resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
resource.returns(0)
@@ -177,6 +203,241 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
end
end
+ describe "when executing guards" do
+
+ before(:each) do
+ resource.not_if.clear
+ resource.only_if.clear
+ resource.guard_interpreter :powershell_script
+ 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
+
+ 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 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 only_if block as true" do
+ resource.only_if "$true"
+ 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 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 as false" do
+ resource.not_if { false }
+ 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 an only_if block as false" do
+ resource.only_if { false }
+ 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 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 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 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 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 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 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 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 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 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 cmdlet exit status for only_if as true" do
+ resource.only_if "cd ."
+ resource.should_skip?(:run).should be_false
+ 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 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 "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 "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 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 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 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 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 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 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 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
+
def get_script_output
script_output = File.read(script_output_path)
end
diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb
index 455c31c283..2d24eee6a3 100644
--- a/spec/functional/resource/registry_spec.rb
+++ b/spec/functional/resource/registry_spec.rb
@@ -118,10 +118,10 @@ describe Chef::Resource::RegistryKey, :windows_only do
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
@events.register(@resource_reporter)
- @run_id = @resource_reporter.run_id
@run_status = Chef::RunStatus.new(@node, @events)
-
@resource_reporter.run_started(@run_status)
+ @run_id = @resource_reporter.run_id
+
@new_resource.cookbook_name = "monkey"
@cookbook_version = double("Cookbook::Version", :version => "1.2.3")
@@ -265,7 +265,7 @@ describe Chef::Resource::RegistryKey, :windows_only do
@new_resource.key(reg_child + '\Slitheen\Raxicoricofallapatorius')
@new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
@new_resource.recursive(false)
- lambda{@new_resource.run_action(:create)}.should_not raise_error
+ @new_resource.run_action(:create) # should not raise_error
@registry.key_exists?(reg_child + '\Slitheen').should == false
@registry.key_exists?(reg_child + '\Slitheen\Raxicoricofallapatorius').should == false
end
@@ -376,7 +376,7 @@ describe Chef::Resource::RegistryKey, :windows_only do
@new_resource.key(reg_child + '\Zygons\Zygor')
@new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
@new_resource.recursive(false)
- lambda{@new_resource.run_action(:create_if_missing)}.should_not raise_error
+ @new_resource.run_action(:create_if_missing) # should not raise_error
@registry.key_exists?(reg_child + '\Zygons').should == false
@registry.key_exists?(reg_child + '\Zygons\Zygor').should == false
end
@@ -547,7 +547,6 @@ describe Chef::Resource::RegistryKey, :windows_only do
@new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
@new_resource.recursive(false)
@new_resource.run_action(:delete_key)
- @new_resource.should_not raise_error
end
it "does nothing if the action is delete_key" do
@new_resource.key(reg_parent + '\OpscodeWhyRun')
diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb
index 0b8a65114c..b983b711da 100644
--- a/spec/functional/win32/versions_spec.rb
+++ b/spec/functional/win32/versions_spec.rb
@@ -22,7 +22,7 @@ if Chef::Platform.windows?
require 'ruby-wmi'
end
-describe "Chef::ReservedNames::Win32::Version", :windows_only do
+describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on_win2k3 do
before do
host = WMI::Win32_OperatingSystem.find(:first)
@@ -57,7 +57,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only do
end
end
end
-
+
context "Win32 version object" do
it "should have have one method for each marketing version" do
versions = 0
@@ -88,7 +88,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only do
for_each_windows_version { |method_name| @version.send(method_name.to_sym) }
end
end
-
+
context "Windows Operating System version" do
it "should match the version from WMI" do
@current_os_version.should include(@version.marketing_name)