summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2008-03-12 09:57:34 -0700
committerAdam Jacob <adam@hjksolutions.com>2008-03-12 09:57:34 -0700
commit8785608a3ff644e4835045396913f0f137706d3c (patch)
tree8509082bf9b21522f984ccf5a042a9203006a140 /spec
parent779a6a5cfba68e95c8a9ed8777d4ff3bf12d9c85 (diff)
downloadchef-8785608a3ff644e4835045396913f0f137706d3c.tar.gz
Adding cookbook support, updating rcov coverage
Diffstat (limited to 'spec')
-rw-r--r--spec/data/cookbooks/openldap/attributes/default.rb9
-rw-r--r--spec/data/cookbooks/openldap/attributes/smokey.rb1
-rw-r--r--spec/data/cookbooks/openldap/definitions/client.rb5
-rw-r--r--spec/data/cookbooks/openldap/definitions/server.rb5
-rw-r--r--spec/data/cookbooks/openldap/ignore0
-rw-r--r--spec/data/cookbooks/openldap/recipes/gigantor.rb3
-rw-r--r--spec/unit/cookbook_collection_spec.rb65
-rw-r--r--spec/unit/cookbook_spec.rb135
8 files changed, 220 insertions, 3 deletions
diff --git a/spec/data/cookbooks/openldap/attributes/default.rb b/spec/data/cookbooks/openldap/attributes/default.rb
index d5ef90f6c4..652fc18a20 100644
--- a/spec/data/cookbooks/openldap/attributes/default.rb
+++ b/spec/data/cookbooks/openldap/attributes/default.rb
@@ -1,11 +1,14 @@
-
case chef_env
when "prod"
ldap_server "ops1prod"
ldap_basedn "dc=hjksolutions,dc=com"
- ldap_replication_password "RiotAct"
+ ldap_replication_password "yes"
when "corp"
ldap_server "ops1prod"
ldap_basedn "dc=hjksolutions,dc=com"
- ldap_replication_password "KickingMeDown"
+ ldap_replication_password "yougotit"
+else
+ ldap_server "ops1prod"
+ ldap_basedn "dc=hjksolutions,dc=com"
+ ldap_replication_password "forsure"
end
diff --git a/spec/data/cookbooks/openldap/attributes/smokey.rb b/spec/data/cookbooks/openldap/attributes/smokey.rb
new file mode 100644
index 0000000000..63f5b56c7f
--- /dev/null
+++ b/spec/data/cookbooks/openldap/attributes/smokey.rb
@@ -0,0 +1 @@
+smokey "robinson" \ No newline at end of file
diff --git a/spec/data/cookbooks/openldap/definitions/client.rb b/spec/data/cookbooks/openldap/definitions/client.rb
new file mode 100644
index 0000000000..37364925fb
--- /dev/null
+++ b/spec/data/cookbooks/openldap/definitions/client.rb
@@ -0,0 +1,5 @@
+define :openldap_client, :mothra => "a big monster" do
+ cat "#{param[:name]}" do
+ pretty_kitty true
+ end
+end
diff --git a/spec/data/cookbooks/openldap/definitions/server.rb b/spec/data/cookbooks/openldap/definitions/server.rb
new file mode 100644
index 0000000000..f189f67ca8
--- /dev/null
+++ b/spec/data/cookbooks/openldap/definitions/server.rb
@@ -0,0 +1,5 @@
+define :openldap_server, :mothra => "a big monster" do
+ cat "#{param[:name]}" do
+ pretty_kitty true
+ end
+end
diff --git a/spec/data/cookbooks/openldap/ignore b/spec/data/cookbooks/openldap/ignore
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/data/cookbooks/openldap/ignore
diff --git a/spec/data/cookbooks/openldap/recipes/gigantor.rb b/spec/data/cookbooks/openldap/recipes/gigantor.rb
new file mode 100644
index 0000000000..4ebbaeb22d
--- /dev/null
+++ b/spec/data/cookbooks/openldap/recipes/gigantor.rb
@@ -0,0 +1,3 @@
+cat "blanket" do
+ pretty_kitty false
+end \ No newline at end of file
diff --git a/spec/unit/cookbook_collection_spec.rb b/spec/unit/cookbook_collection_spec.rb
new file mode 100644
index 0000000000..c2b7b976f9
--- /dev/null
+++ b/spec/unit/cookbook_collection_spec.rb
@@ -0,0 +1,65 @@
+#
+# 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::CookbookCollection do
+# before(:each) do
+# config = Chef::Config.new
+# config.cookbook_path = [
+# File.join(File.dirname(__FILE__), "..", "data", "cookbooks")
+# File.join(File.dirname(__FILE__), "..", "data", "kitchen-cookbooks")
+# ]
+# @cc = Chef::CookbookCollection.new(config)
+# end
+#
+# it "should be a Chef::CookbookCollection object" do
+# @cookbooks.should be_kind_of(Chef::CookbookCollection)
+# end
+#
+# it "should return a list of available cookbooks as []" do
+# @cookbooks[:openldap].should
+# end
+#
+# it "should allow you to iterate over cookbooks with each" do
+# end
+#
+# it "should auto-load a cookbook via [] if it isn't loaded already" do
+# end
+#
+# it "should find all the cookbooks in the cookbook path" do
+# end
+#
+# it "should allow you to override an attribute file via cookbook_path" do
+# end
+#
+# it "should allow you to override a definition file via cookbook_path" do
+# end
+#
+# it "should allow you to override a recipe file via cookbook_path" do
+# end
+#
+# it "should allow you to declare a cookbook as 'final', and not look for any other" do
+# end
+#
+# it "should allwo you to have an 'ignore' file, which skips loading files in later cookbooks" do
+# end
+#
+# end \ No newline at end of file
diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb
new file mode 100644
index 0000000000..1e44f519f7
--- /dev/null
+++ b/spec/unit/cookbook_spec.rb
@@ -0,0 +1,135 @@
+#
+# 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::Cookbook do
+ COOKBOOK_PATH = File.join(File.dirname(__FILE__), "..", "data", "cookbooks", "openldap")
+
+ before(:each) do
+ @cookbook = Chef::Cookbook.new("openldap")
+ end
+
+ it "should be a Chef::Cookbook object" do
+ @cookbook.should be_kind_of(Chef::Cookbook)
+ end
+
+ it "should have a name" do
+ @cookbook.name.should eql("openldap")
+ end
+
+ it "should have a list of attribute files" do
+ @cookbook.attribute_files.should be_kind_of(Array)
+ end
+
+ it "should allow you to set the list of attribute files" do
+ @cookbook.attribute_files = [ "one", "two" ]
+ @cookbook.attribute_files.should eql(["one", "two"])
+ end
+
+ it "should allow you to load all the attributes" do
+ node = Chef::Node.new
+ node.name "Julia Child"
+ node.chef_env false
+ @cookbook.attribute_files = Dir[File.join(COOKBOOK_PATH, "attributes", "**", "*.rb")]
+ node = @cookbook.load_attributes(node)
+ node.ldap_server.should eql("ops1prod")
+ node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
+ node.ldap_replication_password.should eql("forsure")
+ node.smokey.should eql("robinson")
+ end
+
+ it "should raise an ArgumentError if you don't pass a node object to load_attributes" do
+ lambda { @cookbook.load_attributes("snake oil") }.should raise_error(ArgumentError)
+ end
+
+ it "should have a list of definition files" do
+ @cookbook.definition_files.should be_a_kind_of(Array)
+ end
+
+ it "should allow you to set the list of definition files" do
+ @cookbook.definition_files = [ "one", "two" ]
+ @cookbook.definition_files.should eql(["one", "two"])
+ end
+
+ it "should allow you to load all the definitions, returning a hash of ResourceDefinitions by name" do
+ @cookbook.definition_files = Dir[File.join(COOKBOOK_PATH, "definitions", "**", "*.rb")]
+ defs = @cookbook.load_definitions
+ defs.has_key?(:openldap_server).should eql(true)
+ defs[:openldap_server].should be_a_kind_of(Chef::ResourceDefinition)
+ defs.has_key?(:openldap_client).should eql(true)
+ defs[:openldap_client].should be_a_kind_of(Chef::ResourceDefinition)
+ end
+
+ it "should have a list of recipe files" do
+ @cookbook.recipe_files.should be_a_kind_of(Array)
+ end
+
+ it "should allow you to set the list of recipe files" do
+ @cookbook.recipe_files = [ "one", "two" ]
+ @cookbook.recipe_files.should eql(["one", "two"])
+ end
+
+ it "should have a list of recipes by name" do
+ @cookbook.recipe_files = [ "one", "two" ]
+ @cookbook.recipes.detect { |r| r == "openldap::one" }.should eql("openldap::one")
+ @cookbook.recipes.detect { |r| r == "openldap::two" }.should eql("openldap::two")
+ end
+
+ it "should take a file /path.rb, and use the filename minus rb as a recipe name" do
+ @cookbook.recipe_files = [ "/something/one.rb", "/otherthing/two.rb" ]
+ @cookbook.recipes.detect { |r| r == "openldap::one" }.should eql("openldap::one")
+ @cookbook.recipes.detect { |r| r == "openldap::two" }.should eql("openldap::two")
+ end
+
+ it "should take a file path.rb, and use the filename minus rb as a recipe name" do
+ @cookbook.recipe_files = [ "one.rb", "two.rb" ]
+ @cookbook.recipes.detect { |r| r == "openldap::one" }.should eql("openldap::one")
+ @cookbook.recipes.detect { |r| r == "openldap::two" }.should eql("openldap::two")
+ end
+
+ it "should allow you to test for a recipe with recipe?" do
+ @cookbook.recipe_files = [ "one", "two" ]
+ @cookbook.recipe?("one").should eql(true)
+ @cookbook.recipe?("shanghai").should eql(false)
+ end
+
+ it "should allow you to test for a recipe? with a fq recipe name" do
+ @cookbook.recipe_files = [ "one", "two" ]
+ @cookbook.recipe?("openldap::one").should eql(true)
+ @cookbook.recipe?("shanghai::city").should eql(false)
+ end
+
+ it "should allow you to run a recipe by name via load_recipe" do
+ @cookbook.recipe_files = Dir[File.join(COOKBOOK_PATH, "recipes", "**", "*.rb")]
+ node = Chef::Node.new
+ node.name "Julia Child"
+ recipe = @cookbook.load_recipe("openldap::gigantor", node)
+ recipe.recipe_name.should eql("gigantor")
+ recipe.cookbook_name.should eql("openldap")
+ recipe.collection[0].name.should eql("blanket")
+ end
+
+ it "should raise an ArgumentException if you try to load a bad recipe name" do
+ node = Chef::Node.new
+ node.name "Julia Child"
+ lambda { @cookbook.load_recipe("smackdown", node) }.should raise_error(ArgumentError)
+ end
+end \ No newline at end of file