summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <admed@opscode.com>2013-01-25 16:33:43 -0800
committeradamedx <adamed@opscode.com>2013-02-19 09:32:06 -0800
commit63d34bb7887606ee5d55ad70264ff14a90aa3f09 (patch)
treeb2cb0ecabe8bc73195f46bb8e631374207e72ec7
parent5e9dad16efadd17c046654895095dcb7d2052612 (diff)
downloadchef-63d34bb7887606ee5d55ad70264ff14a90aa3f09.tar.gz
OC-4739: OC-4748: Create powershell and batch providers in core Chef
-rw-r--r--lib/chef/exceptions.rb4
-rw-r--r--lib/chef/mixin/windows_architecture_helper.rb47
-rw-r--r--lib/chef/provider/batch.rb35
-rw-r--r--lib/chef/provider/powershell.rb35
-rw-r--r--lib/chef/provider/script.rb16
-rw-r--r--lib/chef/provider/windows_script.rb48
-rw-r--r--lib/chef/providers.rb2
-rw-r--r--lib/chef/resource/batch.rb32
-rw-r--r--lib/chef/resource/powershell.rb32
-rw-r--r--lib/chef/resource/windows_system_script.rb66
-rw-r--r--lib/chef/resources.rb2
-rw-r--r--spec/unit/mixin/windows_architecture_helper_spec.rb83
-rw-r--r--spec/unit/provider/powershell_spec.rb36
-rw-r--r--spec/unit/resource/batch_spec.rb57
-rw-r--r--spec/unit/resource/powershell_spec.rb52
15 files changed, 545 insertions, 2 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index c8654d7801..783a640654 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -97,6 +97,8 @@ class Chef
# Attempting to run windows code on a not-windows node
class Win32NotWindows < RuntimeError; end
class WindowsNotAdmin < RuntimeError; end
+ # Attempting to access a 64-bit only resource on a 32-bit Windows system
+ class Win32ArchitectureIncorrect < RuntimeError; end
class ObsoleteDependencySyntax < ArgumentError; end
class InvalidDataBagPath < ArgumentError; end
@@ -131,7 +133,7 @@ class Chef
class StaleAttributeRead < StandardError; end
#Registry Helper throws the following errors
- class Win32RegArchitectureIncorrect < RuntimeError; end
+ class Win32RegArchitectureIncorrect < Win32ArchitectureIncorrect; end
class Win32RegHiveMissing < ArgumentError; end
class Win32RegKeyMissing < RuntimeError; end
class Win32RegValueMissing < RuntimeError; end
diff --git a/lib/chef/mixin/windows_architecture_helper.rb b/lib/chef/mixin/windows_architecture_helper.rb
new file mode 100644
index 0000000000..7744c20b5f
--- /dev/null
+++ b/lib/chef/mixin/windows_architecture_helper.rb
@@ -0,0 +1,47 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/exceptions'
+
+class Chef
+ module Mixin
+ module WindowsArchitectureHelper
+
+ def node_windows_architecture(node)
+ node[:kernel][:machine].to_sym
+ end
+
+ def node_supports_windows_architecture?(node, desired_architecture)
+ assert_valid_windows_architecture!(desired_architecture)
+ return (node_windows_architecture(node) == :x86_64 || desired_architecture == :i386) ? true : false
+ end
+
+ def valid_windows_architecture?(architecture)
+ return (architecture == :x86_64) || (architecture == :i386)
+ end
+
+ def assert_valid_windows_architecture!(architecture)
+ if ! valid_windows_architecture?(architecture)
+ raise Chef::Exceptions::Win32ArchitectureIncorrect,
+ "The specified architecture was not valid. It must be one of :i386 or :x86_64"
+ end
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/provider/batch.rb b/lib/chef/provider/batch.rb
new file mode 100644
index 0000000000..e4b35b64f3
--- /dev/null
+++ b/lib/chef/provider/batch.rb
@@ -0,0 +1,35 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/provider/windows_script'
+
+class Chef
+ class Provider
+ class Batch < Chef::Provider::WindowsScript
+
+ def initialize (new_resource, run_context)
+ super(new_resource, run_context, '.bat')
+ end
+
+ def flags
+ @new_resource.flags.nil? ? '/c' : new_resource.flags + ' /c'
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/provider/powershell.rb b/lib/chef/provider/powershell.rb
new file mode 100644
index 0000000000..2ae7552197
--- /dev/null
+++ b/lib/chef/provider/powershell.rb
@@ -0,0 +1,35 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/provider/windows_script'
+
+class Chef
+ class Provider
+ class Powershell < Chef::Provider::WindowsScript
+
+ def initialize (new_resource, run_context)
+ super(new_resource, run_context, '.ps1')
+ end
+
+ def flags
+ @new_resource.flags.nil? ? '-ExecutionPolicy RemoteSigned -Command' : new_resource.flags + '-ExecutionPolicy RemoteSigned -Commmand'
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
index 9e5a7d7fe1..5c3d2ebb33 100644
--- a/lib/chef/provider/script.rb
+++ b/lib/chef/provider/script.rb
@@ -29,7 +29,7 @@ class Chef
set_owner_and_group
- @new_resource.command("\"#{@new_resource.interpreter}\" #{@new_resource.flags} \"#{script_file.path}\"")
+ @new_resource.command("\"#{interpreter}\" #{flags} \"#{interpreter_script_path}\"")
super
converge_by(nil) do
# ensure script is unlinked at end of converge!
@@ -52,6 +52,20 @@ class Chef
@script_file && @script_file.close!
end
+ def interpreter
+ @new_resource.interpreter
+ end
+
+ def flags
+ @new_resource.flags
+ end
+
+ protected
+
+ def interpreter_script_path
+ @script_file.path
+ end
+
end
end
end
diff --git a/lib/chef/provider/windows_script.rb b/lib/chef/provider/windows_script.rb
new file mode 100644
index 0000000000..0dfd4d81b3
--- /dev/null
+++ b/lib/chef/provider/windows_script.rb
@@ -0,0 +1,48 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/provider/script'
+
+class Chef
+ class Provider
+ class WindowsScript < Chef::Provider::Script
+
+ def initialize( new_resource, run_context, script_extension='')
+ super( new_resource, run_context )
+ @script_extension = script_extension
+ end
+
+ def flags
+ @new_resource.flags
+ end
+
+ protected
+
+ def script_file
+ base_script_name = "chef-script"
+ temp_file_arguments = [ base_script_name, @script_extension ]
+
+ @script_file ||= Tempfile.open(temp_file_arguments)
+ end
+
+ def interpreter_script_path
+ @script_file.path.gsub(::File::SEPARATOR) { | replace | ::File::ALT_SEPARATOR }
+ end
+ end
+ end
+end
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index be3f487ca3..ae95632eaa 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -16,6 +16,7 @@
# limitations under the License.
#
+require 'chef/provider/batch'
require 'chef/provider/breakpoint'
require 'chef/provider/cookbook_file'
require 'chef/provider/cron'
@@ -36,6 +37,7 @@ require 'chef/provider/ohai'
require 'chef/provider/mdadm'
require 'chef/provider/mount'
require 'chef/provider/package'
+require 'chef/provider/powershell'
require 'chef/provider/remote_directory'
require 'chef/provider/remote_file'
require 'chef/provider/route'
diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb
new file mode 100644
index 0000000000..b44489c549
--- /dev/null
+++ b/lib/chef/resource/batch.rb
@@ -0,0 +1,32 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/resource/windows_system_script'
+require 'chef/mixin/windows_architecture_helper'
+
+class Chef
+ class Resource
+ class Batch < Chef::Resource::WindowsSystemScript
+
+ def initialize(name, run_context=nil)
+ super(name, run_context, :batch, "cmd.exe")
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/resource/powershell.rb b/lib/chef/resource/powershell.rb
new file mode 100644
index 0000000000..35474a1af9
--- /dev/null
+++ b/lib/chef/resource/powershell.rb
@@ -0,0 +1,32 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/resource/script'
+require 'chef/mixin/windows_architecture_helper'
+
+class Chef
+ class Resource
+ class Powershell < Chef::Resource::WindowsSystemScript
+
+ def initialize(name, run_context=nil)
+ super(name, run_context, :powershell, "WindowsPowerShell\\v1.0\\powershell.exe")
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/resource/windows_system_script.rb b/lib/chef/resource/windows_system_script.rb
new file mode 100644
index 0000000000..1bc618aea1
--- /dev/null
+++ b/lib/chef/resource/windows_system_script.rb
@@ -0,0 +1,66 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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 'chef/resource/script'
+require 'chef/mixin/windows_architecture_helper'
+
+class Chef
+ class Resource
+ class WindowsSystemScript < Chef::Resource::Script
+ include Chef::Mixin::WindowsArchitectureHelper
+
+ def architecture(arg=nil)
+ assert_architecture_compatible!(arg) if ! arg.nil?
+ result = set_or_return(
+ :architecture,
+ arg,
+ :kind_of => Symbol
+ )
+ end
+
+ def interpreter
+ target_architecture = architecture.nil? ? node_windows_architecture(node) : architecture
+ path_prefix = (target_architecture == :x86_64) ? INTERPRETER_64_BIT_PATH_PREFIX : INTERPRETER_32_BIT_PATH_PREFIX
+ interpreter_path = "#{path_prefix}\\#{@interpreter_relative_path}"
+ end
+
+ INTERPRETER_64_BIT_PATH_PREFIX = "#{ENV['systemroot']}\\sysnative"
+ INTERPRETER_32_BIT_PATH_PREFIX = "#{ENV['systemroot']}\\system32"
+
+ def initialize(name, run_context=nil, resource_name, interpreter_relative_path)
+ super(name, run_context)
+ @resource_name = resource_name
+ @interpreter_relative_path = interpreter_relative_path
+ init_arch = node_windows_architecture(node)
+ end
+
+ protected
+
+ def node
+ run_context && run_context.node
+ end
+
+ def assert_architecture_compatible!(desired_architecture)
+ if ! node_supports_windows_architecture?(node, desired_architecture)
+ raise Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture '#{desired_architecture.to_s}' on a system with architecture '#{node_windows_architecture(node)}'"
+ end
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb
index 6dea46bfc9..1b295fc4e1 100644
--- a/lib/chef/resources.rb
+++ b/lib/chef/resources.rb
@@ -18,6 +18,7 @@
require 'chef/resource/apt_package'
require 'chef/resource/bash'
+require 'chef/resource/batch'
require 'chef/resource/breakpoint'
require 'chef/resource/cookbook_file'
require 'chef/resource/chef_gem'
@@ -49,6 +50,7 @@ require 'chef/resource/package'
require 'chef/resource/pacman_package'
require 'chef/resource/perl'
require 'chef/resource/portage_package'
+require 'chef/resource/powershell'
require 'chef/resource/python'
require 'chef/resource/registry_key'
require 'chef/resource/remote_directory'
diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb
new file mode 100644
index 0000000000..c7813a5efc
--- /dev/null
+++ b/spec/unit/mixin/windows_architecture_helper_spec.rb
@@ -0,0 +1,83 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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'
+require 'chef/mixin/windows_architecture_helper'
+
+
+
+describe Chef::Mixin::WindowsArchitectureHelper do
+ include Chef::Mixin::WindowsArchitectureHelper
+
+ before do
+ @valid_architectures = [ :i386, :x86_64 ]
+ @invalid_architectures = [ "i386", "x86_64", :x64, :x86, :arm ]
+
+ @node_i386 = Chef::Node.new
+ @node_x86_64 = Chef::Node.new
+ end
+
+ it "returns true when valid architectures are passed to valid_windows_architecture?" do
+ @valid_architectures.each do | architecture |
+ valid_windows_architecture?(architecture).should == true
+ end
+ end
+
+ it "returns false when invalid architectures are passed to valid_windows_architecture?" do
+ @invalid_architectures.each do | architecture |
+ valid_windows_architecture?(architecture).should == false
+ end
+ end
+
+ it "does not raise an exception when a valid architecture is passed to assert_valid_windows_architecture!" do
+ @valid_architectures.each do | architecture |
+ assert_valid_windows_architecture!(architecture)
+ end
+ end
+
+ it "raises an error if an invalid architecture is passed to assert_valid_windows_architecture!" do
+ @invalid_architectures.each do | architecture |
+ begin
+ assert_valid_windows_architecture!(architecture).should raise_error Chef::Exceptions::Win32ArchitectureIncorrect
+ rescue Chef::Exceptions::Win32ArchitectureIncorrect
+ end
+ 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)
+ 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)
+ end
+
+ def enumerate_architecture_node_combinations(only_valid_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 |
+ node_supports_windows_architecture?(new_node, supported_architecture).should == true if only_valid_combinations && (supported_architecture != :x86_64 && node_architecture != :i386 )
+ node_supports_windows_architecture?(new_node, supported_architecture).should == false if ! only_valid_combinations && (supported_architecture == :x86_64 && node_architecture == :i386 )
+ end
+ end
+ end
+end
diff --git a/spec/unit/provider/powershell_spec.rb b/spec/unit/provider/powershell_spec.rb
new file mode 100644
index 0000000000..37b299ebbf
--- /dev/null
+++ b/spec/unit/provider/powershell_spec.rb
@@ -0,0 +1,36 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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::Provider::Powershell, "action_run" do
+
+ before(:each) do
+ @node = Chef::Node.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ @new_resource = Chef::Resource::Powershell.new('run some powershell code')
+# @new_resource.code "$| = 1; print 'i like beans'"
+# @new_resource.interpreter 'perl'
+
+ @provider = Chef::Provider::Powershell.new(@new_resource, @run_context)
+ end
+
+ it "should set the -command flag as the last flag" do
+ @provider.flags.split(' ').pop.should == "-Command"
+ end
+
+end
diff --git a/spec/unit/resource/batch_spec.rb b/spec/unit/resource/batch_spec.rb
new file mode 100644
index 0000000000..1e4d65da7c
--- /dev/null
+++ b/spec/unit/resource/batch_spec.rb
@@ -0,0 +1,57 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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::Batch do
+
+ before(:each) do
+ node = Chef::Node.new
+
+ node.default["kernel"] = Hash.new
+ node.default["kernel"][:machine] = :x86_64.to_s
+
+ run_context = Chef::RunContext.new(node, nil, nil)
+
+ @resource = Chef::Resource::Batch.new("batch_unit_test", run_context)
+
+ end
+
+ it "should create a new Chef::Resource::Batch" do
+ @resource.should be_a_kind_of(Chef::Resource)
+ @resource.should be_a_kind_of(Chef::Resource::Batch)
+ end
+
+ it "should have a resource name of :batch" do
+ @resource.resource_name.should eql(:batch)
+ end
+
+ it "should have an interpreter with a file name of cmd.exe" do
+
+
+ # When rspec-mocks 2.11 is released, switch to constant_stubbing
+ # with const_stub below
+ # stub_const("::File::ALT_SEPARATOR",::File::SEPARATOR).
+ # For now, stub out a method that exists just for this purpose
+# @resource.respond_to?(:windows_separator).should == true
+# @resource.stub(:windows_separator) { ::File::SEPARATOR }
+
+ @resource.interpreter.split('\\').pop.casecmp('cmd.exe').should == 0
+ end
+
+end
diff --git a/spec/unit/resource/powershell_spec.rb b/spec/unit/resource/powershell_spec.rb
new file mode 100644
index 0000000000..fad4ae4eee
--- /dev/null
+++ b/spec/unit/resource/powershell_spec.rb
@@ -0,0 +1,52 @@
+#
+# Author:: Adam Edwards (<adamed@opscode.com>)
+# Copyright:: Copyright (c) 2013 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::Powershell do
+
+ before(:each) do
+ node = Chef::Node.new
+
+ node.default["kernel"] = Hash.new
+ node.default["kernel"][:machine] = :x86_64.to_s
+
+ run_context = Chef::RunContext.new(node, nil, nil)
+
+ @resource = Chef::Resource::Batch.new("batch_unit_test", run_context)
+
+ run_context = Chef::RunContext.new(node, nil, nil)
+
+ @resource = Chef::Resource::Powershell.new("powershell_unit_test", run_context)
+
+ end
+
+ it "should create a new Chef::Resource::Powershell" do
+ @resource.should be_a_kind_of(Chef::Resource)
+ @resource.should be_a_kind_of(Chef::Resource::Powershell)
+ end
+
+ it "should have a resource name of :powershell" do
+ @resource.resource_name.should eql(:powershell)
+ end
+
+ it "should have an interpreter with a file name of powershell.exe" do
+ @resource.interpreter.split('\\').pop.casecmp('powershell.exe').should == 0
+ end
+
+end