diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/chef_spec.rb (renamed from spec/unit/marionette_spec.rb) | 4 | ||||
-rw-r--r-- | spec/unit/compile_spec.rb (renamed from spec/unit/node.rb) | 46 | ||||
-rw-r--r-- | spec/unit/config_spec.rb | 72 | ||||
-rw-r--r-- | spec/unit/mixin/graph_resources_spec.rb | 41 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 108 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 98 | ||||
-rw-r--r-- | spec/unit/resource/file_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/resource_collection_spec.rb | 173 | ||||
-rw-r--r-- | spec/unit/resource_definition_spec.rb | 85 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 108 |
10 files changed, 609 insertions, 136 deletions
diff --git a/spec/unit/marionette_spec.rb b/spec/unit/chef_spec.rb index 7c76c8baeb..a75e3ad548 100644 --- a/spec/unit/marionette_spec.rb +++ b/spec/unit/chef_spec.rb @@ -20,8 +20,8 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper") -describe Marionette do +describe Chef do it "should have a version defined" do - Marionette::VERSION.should match(/(\d+)\.(\d+)\.(\d+)/) + Chef::VERSION.should match(/(\d+)\.(\d+)\.(\d+)/) end end
\ No newline at end of file diff --git a/spec/unit/node.rb b/spec/unit/compile_spec.rb index 57c8cdd7f1..1a986b8f44 100644 --- a/spec/unit/node.rb +++ b/spec/unit/compile_spec.rb @@ -1,3 +1,4 @@ +# # Author:: Adam Jacob (<adam@hjksolutions.com>) # Copyright:: Copyright (c) 2008 HJK Solutions, LLC # License:: GNU General Public License version 2 or later @@ -19,25 +20,26 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper") -describe Marionette::Node do - before(:each) do - @node = Marionette::Node.new("latte") - end - - it "should have a name" do - @resource.name.should eql("latte") - end - - it "should create a new Marionette::Node" do - @resource.should be_a_kind_of(Marionette::Node) - end - - it "should not be valid without a name" do - lambda { @resource.name = nil }.should raise_error(ArgumentError) - end - - it "should always have a string for name" do - lambda { @resource.name = Hash.new }.should raise_error(ArgumentError) - end - -end
\ No newline at end of file +# describe Chef::Compile do +# before(:each) do +# config = Chef::Config.new +# config.cookbook_path = [ File.join(File.dirname(__FILE__), "..", "cookbooks") ] +# @compile = Chef::Compile.new(config) +# end +# +# it "should require a node object to compile" do +# +# end +# +# it "should load up all variables" do +# +# end +# +# it "should load up all definitions" do +# +# end +# +# it "should load up all recipes" do +# +# end +# end
\ No newline at end of file diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb new file mode 100644 index 0000000000..dec94796e0 --- /dev/null +++ b/spec/unit/config_spec.rb @@ -0,0 +1,72 @@ +# +# 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.join(File.dirname(__FILE__), "..", "spec_helper") + +describe Chef::Config do + before(:each) do + @config = Chef::Config.new + end + + it "should load a .rb file in context" do + lambda { + Chef::Config.load_file(File.join(File.dirname(__FILE__), "..", "data", "config.rb")) + }.should_not raise_error + end + + it "should raise a NoMethodError with an explanation if you have a bad config file" do + lambda { + Chef::Config.load_file(File.join(File.dirname(__FILE__), "..", "data", "bad-config.rb")) + }.should raise_error(NoMethodError) + end + + it "should raise an IOError if it can't find the file" do + lambda { + Chef::Config.load_file("/tmp/timmytimmytimmy") + }.should raise_error(IOError) + end + + it "should have a default cookbook_path" do + @config.cookbook_path.should be_kind_of(Array) + end + + it "should allow you to set a cookbook_path with a string" do + @config.cookbook_path("/etc/chef/cookbook") + @config.cookbook_path.should eql(["/etc/chef/cookbook"]) + end + + it "should allow you to set a cookbook_path with multiple strings" do + @config.cookbook_path("/etc/chef/cookbook", "/etc/chef/upstream-cookbooks") + @config.cookbook_path.should eql([ + "/etc/chef/cookbook", + "/etc/chef/upstream-cookbooks" + ]) + end + + it "should allow you to set a cookbook_path with an array" do + @config.cookbook_path ["one", "two"] + @config.cookbook_path.should eql(["one", "two"]) + end + + it "should not allow you to set a cookbook_path with anything else" do + lambda { @config.cookbook_path :symbol }.should raise_error(ArgumentError) + end + +end
\ No newline at end of file diff --git a/spec/unit/mixin/graph_resources_spec.rb b/spec/unit/mixin/graph_resources_spec.rb deleted file mode 100644 index 9fbb4f4c3e..0000000000 --- a/spec/unit/mixin/graph_resources_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# 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.join(File.dirname(__FILE__), "..", "..", "spec_helper") - -describe Marionette::Mixin::GraphResources do - it "should find a resource by symbol and name, or array of names" do - @recipe = Marionette::Recipe.new("one", "two", "three") - %w{monkey dog cat}.each do |name| - @recipe.zen_master name do - peace = true - end - end - doggie = @recipe.resources(:zen_master => "dog") - doggie.name.should eql("dog") # clever, I know - multi_zen = [ "dog", "monkey" ] - zen_array = @recipe.resources(:zen_master => multi_zen) - zen_array.length.should eql(2) - zen_array.each_index do |i| - zen_array[i].name.should eql(multi_zen[i]) - zen_array[i].resource_name.should eql(:zen_master) - end - end -end
\ No newline at end of file diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb new file mode 100644 index 0000000000..e5a92486e5 --- /dev/null +++ b/spec/unit/node_spec.rb @@ -0,0 +1,108 @@ +# +# 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.join(File.dirname(__FILE__), "..", "spec_helper") + +describe Chef::Node do + before(:each) do + @node = Chef::Node.new() + end + + it "should create a new Chef::Node" do + @node.should be_a_kind_of(Chef::Node) + end + + it "should allow you to set a name with name(something)" do + lambda { @node.name("latte") }.should_not raise_error + end + + it "should return the name with name()" do + @node.name("latte") + @node.name.should eql("latte") + end + + it "should always have a string for name" do + lambda { @node.name(Hash.new) }.should raise_error(ArgumentError) + end + + it "should have attributes" do + @node.attribute.should be_a_kind_of(Hash) + end + + it "should allow attributes to be accessed by name or symbol directly on node[]" do + @node.attribute["locust"] = "something" + @node[:locust].should eql("something") + @node["locust"].should eql("something") + end + + it "should return nil if it cannot find an attribute with node[]" do + @node["secret"].should eql(nil) + end + + it "should allow you to query whether an attribute exists with attribute?" do + @node.attribute["locust"] = "something" + @node.attribute?("locust").should eql(true) + @node.attribute?("no dice").should eql(false) + end + + it "should have an array of recipes that should be applied" do + @node.recipes.should be_a_kind_of(Array) + end + + it "should allow you to query whether or not it has a recipe applied with recipe?" do + @node.recipes << "sunrise" + @node.recipe?("sunrise").should eql(true) + @node.recipe?("not at home").should eql(false) + end + + it "should allow you to set recipes with arguments" do + @node.recipes "one", "two" + @node.recipe?("one").should eql(true) + @node.recipe?("two").should eql(true) + end + + it "should allow you to set an attribute via method_missing" do + @node.sunshine "is bright" + @node.attribute[:sunshine].should eql("is bright") + end + + it "should allow you get get an attribute via method_missing" do + @node.sunshine "is bright" + @node.sunshine.should eql("is bright") + end + + it "should raise an ArgumentError if you ask for an attribute that doesn't exist via method_missing" do + lambda { @node.sunshine }.should raise_error(ArgumentError) + end + + it "should load a node from a ruby file" do + @node.from_file(File.join(File.dirname(__FILE__), "..", "data", "nodes", "test.rb")) + @node.name.should eql("ops1prod") + @node.sunshine.should eql("in") + @node.something.should eql("else") + @node.recipes.should eql(["operations-master", "operations-monitoring"]) + end + + it "should raise an exception if the file cannot be found or read" do + lambda { @node.from_file("/tmp/monkeydiving") }.should raise_error(IOError) + end + + +end
\ No newline at end of file diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 69f70e6862..11080a2d82 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -1,3 +1,4 @@ +# # Author:: Adam Jacob (<adam@hjksolutions.com>) # Copyright:: Copyright (c) 2008 HJK Solutions, LLC # License:: GNU General Public License version 2 or later @@ -19,50 +20,69 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper") -describe Marionette::Recipe do +describe Chef::Recipe do before(:each) do - @recipe = Marionette::Recipe.new("hjk", "test", "node") + @recipe = Chef::Recipe.new("hjk", "test", "node") end - it "should load our zen_master resource" do + it "should load a two word (zen_master) resource" do lambda do @recipe.zen_master "monkey" do - peace = true + peace true + end + end.should_not raise_error(ArgumentError) + end + + it "should load a one word (cat) resource" do + lambda do + @recipe.cat "loulou" do + pretty_kitty true end end.should_not raise_error(ArgumentError) end - it "should add our zen_master as a vertex" do + it "should throw an error if you access a resource that we can't find" do + lambda { @recipe.not_home { || } }.should raise_error(NameError) + end + + it "should allow regular errors (not NameErrors) to pass unchanged" do + lambda { + @recipe.cat { || raise ArgumentError, "You Suck" } + }.should raise_error(ArgumentError) + end + + it "should add our zen_master to the collection" do @recipe.zen_master "monkey" do - peace = true - end - @recipe.dg.each_vertex do |v| - next if v == :top - v.should be_kind_of(Marionette::Resource::ZenMaster) + peace true end + @recipe.collection.lookup("zen_master[monkey]").name.should eql("monkey") end - it "should graph our zen masters in the order they appear" do + it "should add our zen masters to the collection in the order they appear" do %w{monkey dog cat}.each do |name| @recipe.zen_master name do - peace = true + peace true end end - index = 0 - @recipe.dg.topsort_iterator do |v| - case v - when :top - index.should eql(0) - when v.name == "monkey" - index.should eql(1) - when v.name == "dog" - index.should eql(2) - when v.name == "cat" - index.should eql(3) + @recipe.collection.each_index do |i| + case i + when 0 + @recipe.collection[i].name.should eql("monkey") + when 1 + @recipe.collection[i].name.should eql("dog") + when 2 + @recipe.collection[i].name.should eql("cat") end - index += 1 end end + + it "should return the new resource after creating it" do + res = @recipe.zen_master "makoto" do + peace true + end + res.resource_name.should eql(:zen_master) + res.name.should eql("makoto") + end it "should handle an instance_eval properly" do code = <<-CODE @@ -73,5 +93,35 @@ CODE lambda { @recipe.instance_eval(code) }.should_not raise_error @recipe.resources(:zen_master => "gnome").name.should eql("gnome") end + + it "should execute defined resources" do + crow_define = Chef::ResourceDefinition.new + crow_define.define :crow, :peace => false, :something => true do + zen_master "lao tzu" do + peace params[:peace] + something params[:something] + end + end + @recipe.definitions[:crow] = crow_define + @recipe.crow "mine" do + peace true + end + @recipe.resources(:zen_master => "lao tzu").name.should eql("lao tzu") + @recipe.resources(:zen_master => "lao tzu").something.should eql(true) + end + + it "should load a node from a ruby file" do + @recipe.from_file(File.join(File.dirname(__FILE__), "..", "data", "recipes", "test.rb")) + res = @recipe.resources(:file => "/etc/nsswitch.conf") + res.name.should eql("/etc/nsswitch.conf") + res.insure.should eql("present") + res.owner.should eql("root") + res.group.should eql("root") + res.mode.should eql(0644) + end + + it "should raise an exception if the file cannot be found or read" do + lambda { @recipe.from_file("/tmp/monkeydiving") }.should raise_error(IOError) + end end
\ No newline at end of file diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index 62b6498473..85aaac1311 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -19,15 +19,15 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper") -describe Marionette::Resource::File do +describe Chef::Resource::File do before(:each) do - @resource = Marionette::Resource::File.new("fakey_fakerton") + @resource = Chef::Resource::File.new("fakey_fakerton") end - it "should create a new Marionette::Resource::File" do - @resource.should be_a_kind_of(Marionette::Resource) - @resource.should be_a_kind_of(Marionette::Resource::File) + it "should create a new Chef::Resource::File" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::File) end it "should have a name" do diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb new file mode 100644 index 0000000000..6f6f195513 --- /dev/null +++ b/spec/unit/resource_collection_spec.rb @@ -0,0 +1,173 @@ +# 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.join(File.dirname(__FILE__), "..", "spec_helper") + +describe Chef::ResourceCollection do + + before(:each) do + @rc = Chef::ResourceCollection.new() + @resource = Chef::Resource::ZenMaster.new("makoto") + end + + it "should return a Chef::ResourceCollection" do + @rc.should be_kind_of(Chef::ResourceCollection) + end + + it "should accept Chef::Resources" do + lambda { @rc[0] = @resource }.should_not raise_error + lambda { @rc[0] = "string" }.should raise_error + end + + it "should accept Chef::Resources through pushing" do + lambda { @rc.push(@resource) }.should_not raise_error + lambda { @rc.push("string") }.should raise_error + end + + it "should allow you to fetch Chef::Resources by position" do + @rc[0] = @resource + @rc[0].should eql(@resource) + end + + it "should accept the << operator" do + lambda { @rc << @resource }.should_not raise_error + end + + it "should allow you to iterate over every resource in the collection" do + load_up_resources + results = Array.new + lambda { + @rc.each do |r| + results << r.name + end + }.should_not raise_error + results.each_index do |i| + case i + when 0 + results[i].should eql("dog") + when 1 + results[i].should eql("cat") + when 2 + results[i].should eql("monkey") + end + end + end + + it "should allow you to iterate over every resource by index" do + load_up_resources + results = Array.new + lambda { + @rc.each_index do |i| + results << @rc[i].name + end + }.should_not raise_error() + results.each_index do |i| + case i + when 0 + results[i].should eql("dog") + when 1 + results[i].should eql("cat") + when 2 + results[i].should eql("monkey") + end + end + end + + it "should allow you to find resources by name via lookup" do + zmr = Chef::Resource::ZenMaster.new("dog") + @rc << zmr + @rc.lookup(zmr.to_s).should eql(zmr) + + zmr = Chef::Resource::ZenMaster.new("cat") + @rc[0] = zmr + @rc.lookup(zmr).should eql(zmr) + + zmr = Chef::Resource::ZenMaster.new("monkey") + @rc.push(zmr) + @rc.lookup(zmr).should eql(zmr) + end + + it "should raise an exception if you send something strange to lookup" do + lambda { @rc.lookup(:symbol) }.should raise_error(ArgumentError) + end + + it "should raise an exception if it cannot find a resource with lookup" do + lambda { @rc.lookup("zen_master[dog]") }.should raise_error(ArgumentError) + end + + it "should find a resource by symbol and name (:zen_master => monkey)" do + load_up_resources + @rc.resources(:zen_master => "monkey").name.should eql("monkey") + end + + it "should find a resource by symbol and array of names (:zen_master => [a,b])" do + load_up_resources + results = @rc.resources(:zen_master => [ "monkey", "dog" ]) + results.length.should eql(2) + check_by_names(results, "monkey", "dog") + end + + it "should find resources of multiple kinds (:zen_master => a, :file => b)" do + load_up_resources + results = @rc.resources(:zen_master => "monkey", :file => "something") + results.length.should eql(2) + check_by_names(results, "monkey", "something") + end + + it "should find a resource by string zen_master[a]" do + load_up_resources + @rc.resources("zen_master[monkey]").name.should eql("monkey") + end + + it "should find resources by strings of zen_master[a,b]" do + load_up_resources + results = @rc.resources("zen_master[monkey,dog]") + results.length.should eql(2) + check_by_names(results, "monkey", "dog") + end + + it "should find resources of multiple types by strings of zen_master[a]" do + load_up_resources + results = @rc.resources("zen_master[monkey]", "file[something]") + results.length.should eql(2) + check_by_names(results, "monkey", "something") + end + + it "should raise an exception if you pass a bad name to resources" do + lambda { @rc.resources("michael jackson") }.should raise_error(ArgumentError) + end + + it "should raise an exception if you pass something other than a string or hash to resource" do + lambda { @rc.resources([Array.new]) }.should raise_error(ArgumentError) + end + + def check_by_names(results, *names) + names.each do |res_name| + results.detect{ |res| res.name == res_name }.should_not eql(nil) + end + end + + def load_up_resources + %w{dog cat monkey}.each do |n| + @rc << Chef::Resource::ZenMaster.new(n) + end + @rc << Chef::Resource::File.new("something") + end + +end
\ No newline at end of file diff --git a/spec/unit/resource_definition_spec.rb b/spec/unit/resource_definition_spec.rb new file mode 100644 index 0000000000..8bcd9c52f9 --- /dev/null +++ b/spec/unit/resource_definition_spec.rb @@ -0,0 +1,85 @@ +# +# 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.join(File.dirname(__FILE__), "..", "spec_helper") + +describe Chef::ResourceDefinition do + before(:each) do + @def = Chef::ResourceDefinition.new() + end + + it "should accept a new definition with a symbol for a name" do + lambda { + @def.define :smoke do + end + }.should_not raise_error(ArgumentError) + lambda { + @def.define "george washington" do + end + }.should raise_error(ArgumentError) + @def.name.should eql(:smoke) + end + + it "should accept a new definition with a hash" do + lambda { + @def.define :smoke, :cigar => "cuban", :cigarette => "marlboro" do + end + }.should_not raise_error(ArgumentError) + end + + it "should expose the prototype hash params in the params hash" do + @def.define :smoke, :cigar => "cuban", :cigarette => "marlboro" do + end + @def.params[:cigar].should eql("cuban") + @def.params[:cigarette].should eql("marlboro") + end + + it "should store the block passed to define as a proc under recipe" do + @def.define :smoke do + "I am what I am" + end + @def.recipe.should be_a_kind_of(Proc) + @def.recipe.call.should eql("I am what I am") + end + + it "should set paramaters based on method_missing" do + @def.mind "to fly" + @def.params[:mind].should eql("to fly") + end + + it "should raise an exception if prototype_params is not a hash" do + lambda { + @def.define :monkey, Array.new do + end + }.should raise_error(ArgumentError) + end + + it "should raise an exception if define is called without a block" do + lambda { + @def.define :monkey + }.should raise_error(ArgumentError) + end + + it "should load a description from a file" do + @def.from_file(File.join(File.dirname(__FILE__), "..", "data", "definitions", "test.rb")) + @def.name.should eql(:rico_suave) + @def.params[:rich].should eql("smooth") + end +end
\ No newline at end of file diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index ccabda6043..f767fe8348 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -1,3 +1,4 @@ +# # Author:: Adam Jacob (<adam@hjksolutions.com>) # Copyright:: Copyright (c) 2008 HJK Solutions, LLC # License:: GNU General Public License version 2 or later @@ -19,17 +20,22 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper") -describe Marionette::Resource do +describe Chef::Resource do before(:each) do - @resource = Marionette::Resource.new("funk") + @resource = Chef::Resource.new("funk") end + it "should create a new Chef::Resource" do + @resource.should be_a_kind_of(Chef::Resource) + end + it "should have a name" do @resource.name.should eql("funk") end - it "should create a new Marionette::Resource" do - @resource.should be_a_kind_of(Marionette::Resource) + it "should let you set a new name" do + @resource.name "monkey" + @resource.name.should eql("monkey") end it "should not be valid without a name" do @@ -46,69 +52,87 @@ describe Marionette::Resource do lambda { @resource.noop "eat it" }.should raise_error(ArgumentError) end - it "should make itself dependent on required resources" do - lambda { - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) - }.should_not raise_error - lambda { - @resource.requires @resource.resources(:zen_master => "coffee") - }.should_not raise_error - - @resource.deps.topsort_iterator.to_a[0].name.should eql("coffee") - @resource.deps.topsort_iterator.to_a[1].name.should eql("funk") + it "should make notified resources appear in the actions hash" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") + @resource.notifies :reload, @resource.resources(:zen_master => "coffee") + @resource.actions[:reload][:delayed][0].name.should eql("coffee") end - it "should make before resources appear later in the graph" do - lambda { - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) - }.should_not raise_error - lambda { - @resource.before @resource.resources(:zen_master => "coffee") - }.should_not raise_error - - @resource.deps.topsort_iterator.to_a[0].name.should eql("funk") - @resource.deps.topsort_iterator.to_a[1].name.should eql("coffee") + it "should make notified resources be capable of acting immediately" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") + @resource.notifies :reload, @resource.resources(:zen_master => "coffee"), :immediate + @resource.actions[:reload][:immediate][0].name.should eql("coffee") end - it "should make notified resources appear in the actions hash" do - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) - @resource.notifies :reload, @resource.resources(:zen_master => "coffee") - @resource.actions[:reload][0].name.should eql("coffee") + it "should raise an exception if told to act in other than :delay or :immediate(ly)" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") + lambda { + @resource.notifies :reload, @resource.resources(:zen_master => "coffee"), :someday + }.should raise_error(ArgumentError) end - it "should make notified resources happen later in the graph" do - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) + it "should allow multiple notified resources appear in the actions hash" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") @resource.notifies :reload, @resource.resources(:zen_master => "coffee") - @resource.deps.topsort_iterator.to_a[0].name.should eql("funk") - @resource.deps.topsort_iterator.to_a[1].name.should eql("coffee") + @resource.actions[:reload][:delayed][0].name.should eql("coffee") + @resource.collection << Chef::Resource::ZenMaster.new("beans") + @resource.notifies :reload, @resource.resources(:zen_master => "beans") + @resource.actions[:reload][:delayed][1].name.should eql("beans") end - it "should make subscribed resources appear in the actions hash" do - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) + it "should make resources appear in the actions hash of subscribed nodes" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") zr = @resource.resources(:zen_master => "coffee") @resource.subscribes :reload, zr - zr.actions[:reload][0].name.should eql("funk") + zr.actions[:reload][:delayed][0].name.should eql("funk") end - - it "should make subscribed resources happen earlier in the graph" do - @resource.dg.add_vertex(Marionette::Resource::ZenMaster.new("coffee")) + + it "should make resources appear in the actions hash of subscribed nodes" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") zr = @resource.resources(:zen_master => "coffee") @resource.subscribes :reload, zr - @resource.deps.topsort_iterator.to_a[1].name.should eql("funk") - @resource.deps.topsort_iterator.to_a[0].name.should eql("coffee") + zr.actions[:reload][:delayed][0].name.should eql("funk") + + @resource.collection << Chef::Resource::ZenMaster.new("bean") + zrb = @resource.resources(:zen_master => "bean") + zrb.subscribes :reload, zr + zr.actions[:reload][:delayed][1].name.should eql("bean") + end + + it "should make subscribed resources be capable of acting immediately" do + @resource.collection << Chef::Resource::ZenMaster.new("coffee") + zr = @resource.resources(:zen_master => "coffee") + @resource.subscribes :reload, zr, :immediately + zr.actions[:reload][:immediate][0].name.should eql("funk") end it "should return a value if not defined" do - zm = Marionette::Resource::ZenMaster.new("coffee") + zm = Chef::Resource::ZenMaster.new("coffee") zm.something(true).should eql(true) zm.something.should eql(true) zm.something(false).should eql(false) zm.something.should eql(false) end + it "should become a string like resource_name[name]" do + zm = Chef::Resource::ZenMaster.new("coffee") + zm.to_s.should eql("zen_master[coffee]") + end + + it "should return the arguments passed with 'is'" do + zm = Chef::Resource::ZenMaster.new("coffee") + res = zm.is("one", "two", "three") + res.should eql([ "one", "two", "three" ]) + end + + it "should allow arguments preceeded by is to methods" do + @resource.noop(@resource.is(true)) + @resource.noop.should eql(true) + end + # it "should serialize to yaml" do # yaml_output = <<-DESC -#--- !ruby/object:Marionette::Resource +#--- !ruby/object:Chef::Resource #alias: #before: #name: funk |