summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2008-04-27 22:44:28 -0700
committerAdam Jacob <adam@hjksolutions.com>2008-04-27 22:44:28 -0700
commitbab9b3459fe41849970e50cb9b96ea62370fbad0 (patch)
treec685354e2798bf08905dca308f9c58a52b94e33a /spec
parent39c0a0994cb5af59e4fbb9fefbc487f6bc21d2fb (diff)
downloadchef-bab9b3459fe41849970e50cb9b96ea62370fbad0.tar.gz
chef compiles
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/chef/provider/easy.rb37
-rw-r--r--spec/lib/chef/provider/snakeoil.rb37
-rw-r--r--spec/lib/chef/resource/cat.rb3
-rw-r--r--spec/unit/chef_spec.rb2
-rw-r--r--spec/unit/compile_spec.rb12
-rw-r--r--spec/unit/log/formatter_spec.rb5
-rw-r--r--spec/unit/mixin/params_validate_spec.rb33
-rw-r--r--spec/unit/node_spec.rb5
-rw-r--r--spec/unit/platform_spec.rb211
-rw-r--r--spec/unit/provider/file_spec.rb19
-rw-r--r--spec/unit/provider_spec.rb4
-rw-r--r--spec/unit/resource/directory_spec.rb81
-rw-r--r--spec/unit/resource_spec.rb1
-rw-r--r--spec/unit/runner_spec.rb105
14 files changed, 548 insertions, 7 deletions
diff --git a/spec/lib/chef/provider/easy.rb b/spec/lib/chef/provider/easy.rb
new file mode 100644
index 0000000000..b637efa768
--- /dev/null
+++ b/spec/lib/chef/provider/easy.rb
@@ -0,0 +1,37 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+class Chef
+ class Provider
+ class Easy < Chef::Provider
+ def load_current_resource
+ true
+ end
+
+ def action_sell
+ true
+ end
+
+ def action_buy
+ true
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/lib/chef/provider/snakeoil.rb b/spec/lib/chef/provider/snakeoil.rb
new file mode 100644
index 0000000000..0486402686
--- /dev/null
+++ b/spec/lib/chef/provider/snakeoil.rb
@@ -0,0 +1,37 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+class Chef
+ class Provider
+ class SnakeOil < Chef::Provider
+ def load_current_resource
+ true
+ end
+
+ def action_sell
+ true
+ end
+
+ def action_buy
+ true
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/lib/chef/resource/cat.rb b/spec/lib/chef/resource/cat.rb
index 5b66c9cabd..a0456d6b45 100644
--- a/spec/lib/chef/resource/cat.rb
+++ b/spec/lib/chef/resource/cat.rb
@@ -21,9 +21,12 @@ class Chef
class Resource
class Cat < Chef::Resource
+ attr_accessor :action
+
def initialize(name, collection=nil)
@resource_name = :cat
super(name, collection)
+ @action = "sell"
end
def pretty_kitty(arg=nil)
diff --git a/spec/unit/chef_spec.rb b/spec/unit/chef_spec.rb
index cfb6cd4dac..de8042552a 100644
--- a/spec/unit/chef_spec.rb
+++ b/spec/unit/chef_spec.rb
@@ -24,4 +24,4 @@ describe Chef do
it "should have a version defined" do
Chef::VERSION.should match(/(\d+)\.(\d+)\.(\d+)/)
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/compile_spec.rb b/spec/unit/compile_spec.rb
index 49d5930acb..b6cde6582c 100644
--- a/spec/unit/compile_spec.rb
+++ b/spec/unit/compile_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Compile do
end
it "should have a Chef::ResourceCollection" do
- @compile.resource_collection.should be_a_kind_of(Chef::ResourceCollection)
+ @compile.collection.should be_a_kind_of(Chef::ResourceCollection)
end
it "should have a hash of Definitions" do
@@ -58,11 +58,11 @@ describe Chef::Compile do
@compile.load_node("compile")
@compile.load_definitions
lambda { @compile.load_recipes }.should_not raise_error
- @compile.resource_collection[0].to_s.should == "cat[einstein]"
- @compile.resource_collection[1].to_s.should == "cat[loulou]"
- @compile.resource_collection[2].to_s.should == "cat[birthday]"
- @compile.resource_collection[3].to_s.should == "cat[peanut]"
- @compile.resource_collection[4].to_s.should == "cat[fat peanut]"
+ @compile.collection[0].to_s.should == "cat[einstein]"
+ @compile.collection[1].to_s.should == "cat[loulou]"
+ @compile.collection[2].to_s.should == "cat[birthday]"
+ @compile.collection[3].to_s.should == "cat[peanut]"
+ @compile.collection[4].to_s.should == "cat[fat peanut]"
end
end \ No newline at end of file
diff --git a/spec/unit/log/formatter_spec.rb b/spec/unit/log/formatter_spec.rb
index e7518ead87..6651feab2e 100644
--- a/spec/unit/log/formatter_spec.rb
+++ b/spec/unit/log/formatter_spec.rb
@@ -44,4 +44,9 @@ describe Chef::Log::Formatter do
@formatter.call("monkey", Time.new, "test", "mos def").should == "[#{time.rfc2822}] monkey: mos def\n"
end
+ it "should allow you to turn the time on and off in the output" do
+ Chef::Log::Formatter.show_time = false
+ @formatter.call("monkey", Time.new, "test", "mos def").should == "monkey: mos def\n"
+ end
+
end \ No newline at end of file
diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb
index 3ade2b3c2d..2790f2b14a 100644
--- a/spec/unit/mixin/params_validate_spec.rb
+++ b/spec/unit/mixin/params_validate_spec.rb
@@ -295,4 +295,37 @@ describe Chef::Mixin::ParamsValidate do
@vo.validate({ "one" => "two" }, { :one => { :regex => /^two$/ }})
}.should_not raise_error(ArgumentError)
end
+
+ it "should allow an array to kind_of" do
+ lambda {
+ @vo.validate(
+ {:one => "string"},
+ {
+ :one => {
+ :kind_of => [ String, Array ]
+ }
+ }
+ )
+ }.should_not raise_error(ArgumentError)
+ lambda {
+ @vo.validate(
+ {:one => ["string"]},
+ {
+ :one => {
+ :kind_of => [ String, Array ]
+ }
+ }
+ )
+ }.should_not raise_error(ArgumentError)
+ lambda {
+ @vo.validate(
+ {:one => Hash.new},
+ {
+ :one => {
+ :kind_of => [ String, Array ]
+ }
+ }
+ )
+ }.should raise_error(ArgumentError)
+ end
end \ No newline at end of file
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index c72aea0b7d..0ea4d864d4 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -171,4 +171,9 @@ describe Chef::Node do
list[2].should == "test"
end
+ it "should turn into a string like node[name]" do
+ @node.name("airplane")
+ @node.to_s.should eql("node[airplane]")
+ end
+
end \ No newline at end of file
diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb
new file mode 100644
index 0000000000..4f0a5e5288
--- /dev/null
+++ b/spec/unit/platform_spec.rb
@@ -0,0 +1,211 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+
+describe Chef::Platform do
+ before(:each) do
+ Chef::Platform.platforms = {
+ :darwin => {
+ "9.2.2" => {
+ :file => "darwinian",
+ :else => "thing"
+ },
+ :default => {
+ :file => "old school",
+ :snicker => "snack"
+ }
+ },
+ :mars_volta => {
+ },
+ :default => {
+ :file => Chef::Provider::File,
+ :pax => "brittania",
+ :cat => "nice"
+ }
+ }
+ end
+
+ it "should allow you to look up a platform by name and version, returning the provider map for it" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql("darwinian")
+ end
+
+ it "should use the default providers for an os if the specific version does not exist" do
+ pmap = Chef::Platform.find("Darwin", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql("old school")
+ end
+
+ it "should use the default providers if the os doesn't give me a default, but does exist" do
+ pmap = Chef::Platform.find("mars_volta", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql(Chef::Provider::File)
+ end
+
+ it "should use the default provider if the os does not exist" do
+ pmap = Chef::Platform.find("AIX", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql(Chef::Provider::File)
+ end
+
+ it "should merge the defaults for an os with the specific version" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap[:file].should eql("darwinian")
+ pmap[:snicker].should eql("snack")
+ end
+
+ it "should merge the defaults for an os with the universal defaults" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap[:file].should eql("darwinian")
+ pmap[:pax].should eql("brittania")
+ end
+
+ it "should allow you to look up a provider for a platform directly by symbol" do
+ Chef::Platform.find_provider("Darwin", "9.2.2", :file).should eql("darwinian")
+ end
+
+ it "should raise an exception if a provider cannot be found for a resource type" do
+ lambda { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.should raise_error(ArgumentError)
+ end
+
+ it "should look up a provider for a resource with a Chef::Resource object" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ Chef::Platform.find_provider("Darwin", "9.2.2", kitty)
+ end
+
+ it "should look up a provider with a node and a Chef::Resource object" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.operatingsystem("Darwin")
+ node.operatingsystemversion("9.2.2")
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("nice")
+ end
+
+ it "should prefer lsbdistid over operatingsystem when looking up via node" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.operatingsystem("Darwin")
+ node.operatingsystemversion("9.2.2")
+ node.lsbdistid("Not Linux")
+ Chef::Platform.set(
+ :platform => :not_linux,
+ :resource => :cat,
+ :provider => "bourbon"
+ )
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
+ end
+
+ it "should prefer macosx_productnmae over operatingsystem when looking up via node" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.operatingsystem("Darwin")
+ node.operatingsystemversion("9.2.2")
+ node.macosx_productname("Mac OS X")
+ Chef::Platform.set(
+ :platform => :mac_os_x,
+ :resource => :cat,
+ :provider => "bourbon"
+ )
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
+ end
+
+ it "should prefer lsbdistrelease over operatingsystem when looking up via node" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.operatingsystem("Darwin")
+ node.operatingsystemversion("9.2.2")
+ node.lsbdistrelease("10")
+ Chef::Platform.set(
+ :platform => :darwin,
+ :version => "10",
+ :resource => :cat,
+ :provider => "bourbon"
+ )
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
+ end
+
+ it "should prefer macosx_productversion over operatingsystem when looking up via node" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.operatingsystem("Darwin")
+ node.operatingsystemversion("9.2.2")
+ node.macosx_productversion("10")
+ Chef::Platform.set(
+ :platform => :darwin,
+ :version => "10",
+ :resource => :cat,
+ :provider => "bourbon"
+ )
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
+ end
+
+ it "should update the provider map with map" do
+ Chef::Platform.set(
+ :platform => :darwin,
+ :version => "9.2.2",
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:darwin]["9.2.2"][:file].should eql("masterful")
+ Chef::Platform.set(
+ :platform => :darwin,
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:darwin][:default][:file].should eql("masterful")
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ Chef::Platform.set(
+ :platform => :hero,
+ :version => "9.2.2",
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:hero]["9.2.2"][:file].should eql("masterful")
+
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ Chef::Platform.platforms = {}
+
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ end
+
+
+end \ No newline at end of file
diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb
index 4a98e88df0..3b894ad02a 100644
--- a/spec/unit/provider/file_spec.rb
+++ b/spec/unit/provider/file_spec.rb
@@ -171,12 +171,14 @@ describe Chef::Provider::File do
@provider.load_current_resource
@provider.new_resource.stub!(:owner).and_return(9982398)
@provider.new_resource.stub!(:group).and_return(9982398)
+ @provider.new_resource.stub!(:mode).and_return(0755)
@provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo")
File.stub!(:chown).and_return(1)
File.should_receive(:chown).with(nil, 9982398, @provider.new_resource.path)
File.stub!(:chown).and_return(1)
File.should_receive(:chown).with(9982398, nil, @provider.new_resource.path)
File.stub!(:open).and_return(1)
+ File.should_receive(:chmod).with(0755, @provider.new_resource.path).and_return(1)
File.should_receive(:open).with(@provider.new_resource.path, "w+")
@provider.action_create
end
@@ -190,4 +192,21 @@ describe Chef::Provider::File do
@provider.action_delete
end
+ it "should raise an error if it cannot delete the file" do
+ @provider.load_current_resource
+ @provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo")
+ File.should_receive("exists?").with(@provider.new_resource.path).and_return(false)
+ lambda { @provider.action_delete }.should raise_error()
+ end
+
+ it "should update the atime/mtime on action_touch" do
+ @provider.load_current_resource
+ @provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo")
+ File.should_receive(:utime).once.and_return(1)
+ File.stub!(:open).and_return(1)
+ File.stub!(:chown).and_return(1)
+ File.stub!(:chmod).and_return(1)
+ @provider.action_touch
+ end
+
end \ No newline at end of file
diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb
index 71cc1a47e3..6a28120478 100644
--- a/spec/unit/provider_spec.rb
+++ b/spec/unit/provider_spec.rb
@@ -43,4 +43,8 @@ describe Chef::Provider do
it "should have nil for current_resource by default" do
@provider.current_resource.should eql(nil)
end
+
+ it "should return true for action_nothing" do
+ @provider.action_nothing.should eql(true)
+ end
end \ No newline at end of file
diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb
new file mode 100644
index 0000000000..18fffb01ff
--- /dev/null
+++ b/spec/unit/resource/directory_spec.rb
@@ -0,0 +1,81 @@
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Chef::Resource::Directory do
+
+ before(:each) do
+ @resource = Chef::Resource::Directory.new("fakey_fakerton")
+ end
+
+ it "should create a new Chef::Resource::Directory" do
+ @resource.should be_a_kind_of(Chef::Resource)
+ @resource.should be_a_kind_of(Chef::Resource::File)
+ @resource.should be_a_kind_of(Chef::Resource::Directory)
+ end
+
+ it "should have a name" do
+ @resource.name.should eql("fakey_fakerton")
+ end
+
+ it "should have a default action of 'create'" do
+ @resource.action.should eql("create")
+ end
+
+ it "should accept create or delete for action" do
+ lambda { @resource.action "create" }.should_not raise_error(ArgumentError)
+ lambda { @resource.action "delete" }.should_not raise_error(ArgumentError)
+ lambda { @resource.action "blues" }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a group name or id for group" do
+ lambda { @resource.group "root" }.should_not raise_error(ArgumentError)
+ lambda { @resource.group 123 }.should_not raise_error(ArgumentError)
+ lambda { @resource.group "root*goo" }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a valid unix file mode" do
+ lambda { @resource.mode 0444 }.should_not raise_error(ArgumentError)
+ lambda { @resource.mode 444 }.should_not raise_error(ArgumentError)
+ lambda { @resource.mode 4 }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a user name or id for owner" do
+ lambda { @resource.owner "root" }.should_not raise_error(ArgumentError)
+ lambda { @resource.owner 123 }.should_not raise_error(ArgumentError)
+ lambda { @resource.owner "root*goo" }.should raise_error(ArgumentError)
+ end
+
+ it "should use the object name as the path by default" do
+ @resource.path.should eql("fakey_fakerton")
+ end
+
+ it "should accept a string as the path" do
+ lambda { @resource.path "/tmp" }.should_not raise_error(ArgumentError)
+ lambda { @resource.path Hash.new }.should raise_error(ArgumentError)
+ end
+
+ it "should allow you to have specify whether the action is recursive with true/false" do
+ lambda { @resource.recursive true }.should_not raise_error(ArgumentError)
+ lambda { @resource.recursive false }.should_not raise_error(ArgumentError)
+ lambda { @resource.recursive "monkey" }.should raise_error(ArgumentError)
+ end
+
+end \ No newline at end of file
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index d6db1f2d74..be9a7cc3aa 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -129,6 +129,7 @@ describe Chef::Resource do
@resource.noop(@resource.is(true))
@resource.noop.should eql(true)
end
+
# it "should serialize to yaml" do
# yaml_output = <<-DESC
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
new file mode 100644
index 0000000000..2a5c613cc7
--- /dev/null
+++ b/spec/unit/runner_spec.rb
@@ -0,0 +1,105 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: GNU General Public License version 2 or later
+#
+# This program and entire repository is free software; you can
+# redistribute it and/or modify it under the terms of the GNU
+# General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+
+describe Chef::Runner do
+ before(:each) do
+ @mock_node = mock("Node", :null_object => true)
+ @mock_collection = mock("Resource Collection", :null_object => true)
+ @mock_provider = mock("Provider", :null_object => true)
+ @mock_resource = mock("Resource", :null_object => true)
+ new_runner
+ end
+
+ it "should require a Node and a ResourceCollection" do
+ @mock_node.should_receive(:kind_of?).once.and_return(true)
+ @mock_collection.should_receive(:kind_of?).once.and_return(true)
+ runner = Chef::Runner.new(@mock_node, @mock_collection)
+ runner.should be_a_kind_of(Chef::Runner)
+ end
+
+ it "should raise an exception if you pass the wrong kind of object to new" do
+ @mock_node.stub!(:kind_of?).and_return(false)
+ @mock_collecton.stub!(:kind_of?).and_return(false)
+ lambda { Chef::Runner.new(@mock_node, @mock_collection) }.should raise_error(ArgumentError)
+ end
+
+ it "should pass each resource in the collection to a provider" do
+ @collection.should_receive(:each).once
+ @runner.converge
+ end
+
+ it "should use the provider specified by the resource (if it has one)" do
+ provider = Chef::Provider::Easy.new(@node, @collection[0])
+ @collection[0].should_receive(:provider).once.and_return(Chef::Provider::Easy)
+ Chef::Provider::Easy.should_receive(:new).once.and_return(provider)
+ @runner.converge
+ end
+
+ it "should use the platform provider if it has one" do
+ Chef::Platform.should_receive(:find_provider_for_node).once.and_return(Chef::Provider::SnakeOil)
+ @runner.converge
+ end
+
+ it "should run the action for each resource" do
+ Chef::Platform.should_receive(:find_provider_for_node).once.and_return(Chef::Provider::SnakeOil)
+ provider = Chef::Provider::SnakeOil.new(@node, @collection[0])
+ provider.should_receive(:action_sell).once.and_return(true)
+ Chef::Provider::SnakeOil.should_receive(:new).once.and_return(provider)
+ @runner.converge
+ end
+
+ it "should execute immediate actions on changed resources" do
+ Chef::Platform.should_receive(:find_provider_for_node).exactly(3).times.and_return(Chef::Provider::SnakeOil)
+ provider = Chef::Provider::SnakeOil.new(@node, @collection[0])
+ Chef::Provider::SnakeOil.should_receive(:new).exactly(3).times.and_return(provider)
+ @collection << Chef::Resource::Cat.new("peanut", @collection)
+ @collection[1].notifies :buy, @collection[0], :immediately
+ @collection[1].updated = true
+ provider.should_receive(:action_buy).once.and_return(true)
+ @runner.converge
+ end
+
+ it "should execute delayed actions on changed resources" do
+ Chef::Platform.should_receive(:find_provider_for_node).exactly(3).times.and_return(Chef::Provider::SnakeOil)
+ provider = Chef::Provider::SnakeOil.new(@node, @collection[0])
+ Chef::Provider::SnakeOil.should_receive(:new).exactly(3).times.and_return(provider)
+ @collection << Chef::Resource::Cat.new("peanut", @collection)
+ @collection[1].notifies :buy, @collection[0], :delayed
+ @collection[1].updated = true
+ provider.should_receive(:action_buy).once.and_return(true)
+ @runner.converge
+ end
+
+ def new_runner
+ @node = Chef::Node.new
+ @node.name "latte"
+ @node.operatingsystem "mac_os_x"
+ @node.operatingsystemversion "10.5.1"
+ @collection = Chef::ResourceCollection.new()
+ @collection << Chef::Resource::Cat.new("loulou", @collection)
+ Chef::Platform.set(
+ :resource => :cat,
+ :provider => Chef::Provider::SnakeOil
+ )
+ @runner = Chef::Runner.new(@node, @collection)
+ end
+end \ No newline at end of file