diff options
author | Salim Alam <salam@chef.io> | 2015-08-13 14:25:48 -0700 |
---|---|---|
committer | Salim Alam <salam@chef.io> | 2015-08-19 11:08:17 -0700 |
commit | 6c4cd5c6d5c40baca723bf95cdbccdda59021198 (patch) | |
tree | f2d6357705440c11467b46c60eac0b4c5ddb871e /spec | |
parent | fe6676bab51390429674b0ecd4670924ffb09cc5 (diff) | |
download | chef-6c4cd5c6d5c40baca723bf95cdbccdda59021198.tar.gz |
Enable 64-bit support for Powershell and Batch scripts
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/powershell_script_spec.rb | 26 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/platform_helpers.rb | 8 | ||||
-rw-r--r-- | spec/unit/mixin/windows_architecture_helper_spec.rb | 21 |
4 files changed, 42 insertions, 15 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index a8e51f4d9d..2e8abedac5 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -229,8 +229,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end - context "when running on a 32-bit version of Windows", :windows32_only do - + context "when running on a 32-bit version of Ruby", :ruby32_only do it "executes a script with a 32-bit process if process architecture :i386 is specified" do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:i386) @@ -240,15 +239,28 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do expect(source_contains_case_insensitive_content?( get_script_output, 'x86' )).to eq(true) end - it "raises an exception if :x86_64 process architecture is specified" do - begin - expect(resource.architecture(:x86_64)).to raise_error Chef::Exceptions::Win32ArchitectureIncorrect - rescue Chef::Exceptions::Win32ArchitectureIncorrect + context "when running on a 64-bit version of Windows", :windows64_only do + it "executes a script with a 64-bit process if :x86_64 arch is specified" do + resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") + resource.architecture(:x86_64) + resource.returns(0) + resource.run_action(:run) + + expect(source_contains_case_insensitive_content?( get_script_output, 'AMD64' )).to eq(true) + end + end + + context "when running on a 32-bit version of Windows", :windows32_only do + it "raises an exception if :x86_64 process architecture is specified" do + begin + expect(resource.architecture(:x86_64)).to raise_error Chef::Exceptions::Win32ArchitectureIncorrect + rescue Chef::Exceptions::Win32ArchitectureIncorrect + end end end end - context "when running on a 64-bit version of Windows", :windows64_only do + context "when running on a 64-bit version of Ruby", :ruby64_only do it "executes a script with a 64-bit process if :x86_64 arch is specified" do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:x86_64) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b55ba9de0..d0d02f1a2a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -130,6 +130,8 @@ RSpec.configure do |config| config.filter_run_excluding :windows_2008r2_or_later => true unless windows_2008r2_or_later? config.filter_run_excluding :windows64_only => true unless windows64? config.filter_run_excluding :windows32_only => true unless windows32? + config.filter_run_excluding :ruby64_only => true unless ruby_64bit? + config.filter_run_excluding :ruby32_only => true unless ruby_32bit? config.filter_run_excluding :windows_powershell_dsc_only => true unless windows_powershell_dsc? config.filter_run_excluding :windows_powershell_no_dsc_only => true unless ! windows_powershell_dsc? config.filter_run_excluding :windows_domain_joined_only => true unless windows_domain_joined? diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index da0313758b..1cfad05172 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -26,6 +26,14 @@ def ruby_20? !!(RUBY_VERSION =~ /^2.0/) end +def ruby_64bit? + !!(RbConfig::CONFIG['host_cpu'] =~ /x86_64/) +end + +def ruby_32bit? + !!(RbConfig::CONFIG['host_cpu'] =~ /i686/) +end + def windows? !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb index 3803d69371..55eca28dc2 100644 --- a/spec/unit/mixin/windows_architecture_helper_spec.rb +++ b/spec/unit/mixin/windows_architecture_helper_spec.rb @@ -60,23 +60,28 @@ describe Chef::Mixin::WindowsArchitectureHelper do end end - it "returns true for each supported desired architecture for all nodes with each valid architecture passed to node_supports_windows_architecture" do - enumerate_architecture_node_combinations(true) + it "returns true only for supported desired architecture passed to node_supports_windows_architecture" do + with_node_architecture_combinations do | node, desired_arch | + expect(node_supports_windows_architecture?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64 || desired_arch == :i386 ) + expect(node_supports_windows_architecture?(node, desired_arch)).to be false if (node_windows_architecture(node) == :i386 && desired_arch == :x86_64 ) + end end - it "returns false for each unsupported desired architecture for all nodes with each valid architecture passed to node_supports_windows_architecture?" do - enumerate_architecture_node_combinations(true) + it "returns true only when forced_32bit_override_required? has 64-bit node architecture and 32-bit desired architecture" do + with_node_architecture_combinations do | node, desired_arch | + expect(forced_32bit_override_required?(node, desired_arch)).to be true if ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows?) + expect(forced_32bit_override_required?(node, desired_arch)).to be false if ! ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386)) + end end - def enumerate_architecture_node_combinations(only_valid_combinations) + def with_node_architecture_combinations @valid_architectures.each do | node_architecture | new_node = Chef::Node.new new_node.default["kernel"] = Hash.new new_node.default["kernel"][:machine] = node_architecture.to_s - @valid_architectures.each do | supported_architecture | - expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(true) if only_valid_combinations && (supported_architecture != :x86_64 && node_architecture != :i386 ) - expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(false) if ! only_valid_combinations && (supported_architecture == :x86_64 && node_architecture == :i386 ) + @valid_architectures.each do | architecture | + yield new_node, architecture if block_given? end end end |