diff options
author | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
---|---|---|
committer | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
commit | c5d33c1298834ce40b8fbf344f281045771b5371 (patch) | |
tree | 1f0d4c7eab1eb379b544282a7ce48052acf719a5 /spec | |
parent | 3d14601aea23dee3899d097324875274da419d84 (diff) | |
download | chef-c5d33c1298834ce40b8fbf344f281045771b5371.tar.gz |
big refactor of the repo layout. move to a chef gem and a chef-server gem all with proper deps
Diffstat (limited to 'spec')
90 files changed, 0 insertions, 5816 deletions
diff --git a/spec/chef_server/controllers/log/merb_test.log b/spec/chef_server/controllers/log/merb_test.log deleted file mode 100644 index 86fbe4b9cb..0000000000 --- a/spec/chef_server/controllers/log/merb_test.log +++ /dev/null @@ -1,4 +0,0 @@ -Tue, 27 May 2008 00:52:34 GMT ~ info ~ Logfile created - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions diff --git a/spec/chef_server/controllers/nodes_spec.rb b/spec/chef_server/controllers/nodes_spec.rb deleted file mode 100644 index 65c2df301a..0000000000 --- a/spec/chef_server/controllers/nodes_spec.rb +++ /dev/null @@ -1,232 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.join(File.dirname(__FILE__), "..", 'spec_helper.rb') -# -# describe Nodes, "index action" do -# it "should get a list of all the nodes" do -# Chef::Node.should_receive(:list).and_return(["one"]) -# dispatch_to(Nodes, :index) do |c| -# c.stub!(:display) -# end -# end -# -# it "should send a list of nodes to display" do -# Chef::Node.stub!(:list).and_return(["one"]) -# dispatch_to(Nodes, :index) do |c| -# c.should_receive(:display).with(["one"]) -# end -# end -# end -# -# describe Nodes, "show action" do -# it "should load a node from the filestore based on the id" do -# node = stub("Node", :null_object => true) -# Chef::Node.should_receive(:load).with("bond").once.and_return(node) -# dispatch_to(Nodes, :show, { :id => "bond" }) do |c| -# c.should_receive(:display).with(node).once.and_return(true) -# end -# end -# -# it "should return 200 on a well formed request" do -# node = stub("Node", :null_object => true) -# Chef::Node.should_receive(:load).with("bond").once.and_return(node) -# controller = dispatch_to(Nodes, :show, { :id => "bond" }) do |c| -# c.stub!(:display) -# end -# controller.status.should eql(200) -# end -# -# it "should raise a BadRequest if the id is not found" do -# Chef::Node.should_receive(:load).with("bond").once.and_raise(RuntimeError) -# lambda { -# dispatch_to(Nodes, :show, { :id => "bond" }) -# }.should raise_error(Merb::ControllerExceptions::BadRequest) -# end -# end -# -# describe Nodes, "create action" do -# it "should create a node from an inflated object" do -# mnode = mock("Node", :null_object => true) -# mnode.stub!(:name).and_return("bond") -# mnode.should_receive(:save).once.and_return(true) -# controller = dispatch_to(Nodes, :create) do |c| -# c.stub!(:params).and_return({ "inflated_object" => mnode }) -# c.stub!(:session).and_return({ -# :openid => 'http://localhost/openid/server/node/bond', -# :level => :node, -# :node_name => "bond", -# }) -# c.stub!(:display) -# end -# controller.status.should eql(202) -# end -# -# it "should raise an exception if it cannot inflate an object" do -# lambda { -# dispatch_to(Nodes, :create) do |c| -# c.stub!(:params).and_return({ }) -# end -# }.should raise_error(Merb::Controller::BadRequest) -# end -# end -# -# describe Nodes, "update action" do -# it "should update a node from an inflated object" do -# mnode = mock("Node", :null_object => true) -# mnode.stub!(:name).and_return("one") -# Chef::FileStore.should_receive(:store).with("node", "one", mnode).once.and_return(true) -# controller = dispatch_to(Nodes, :update, { :id => "one" }) do |c| -# c.stub!(:session).and_return({ -# :openid => 'http://localhost/openid/server/node/one', -# :level => :node, -# :node_name => "one", -# }) -# c.stub!(:params).and_return({ "inflated_object" => mnode }) -# c.stub!(:display) -# end -# controller.status.should eql(202) -# end -# -# it "should raise an exception if it cannot inflate an object" do -# lambda { dispatch_to(Nodes, :update) }.should raise_error(Merb::Controller::BadRequest) -# end -# end -# -# describe Nodes, "destroy action" do -# def do_destroy -# dispatch_to(Nodes, :destroy, { :id => "one" }) do |c| -# c.stub!(:display) -# end -# end -# -# it "should load the node it's about to destroy from the filestore" do -# mnode = stub("Node", :null_object => true) -# Chef::FileStore.should_receive(:load).with("node", "one").once.and_return(mnode) -# Chef::FileStore.stub!(:delete) -# do_destroy -# end -# -# it "should raise an exception if it cannot find the node to destroy" do -# Chef::FileStore.should_receive(:load).with("node", "one").once.and_raise(RuntimeError) -# lambda { do_destroy }.should raise_error(Merb::Controller::BadRequest) -# end -# -# it "should remove the node from the filestore" do -# mnode = stub("Node", :null_object => true) -# Chef::FileStore.stub!(:load).with("node", "one").and_return(mnode) -# Chef::FileStore.should_receive(:delete).with("node", "one") -# do_destroy -# end -# -# it "should remove the node from the search index" do -# mnode = stub("Node", :null_object => true) -# Chef::FileStore.stub!(:load).with("node", "one").and_return(mnode) -# Chef::FileStore.stub!(:delete) -# do_destroy -# end -# -# it "should return the node it just deleted" do -# mnode = stub("Node", :null_object => true) -# Chef::FileStore.stub!(:load).with("node", "one").and_return(mnode) -# Chef::FileStore.stub!(:delete) -# dispatch_to(Nodes, :destroy, { :id => "one" }) do |c| -# c.should_receive(:display).once.with(mnode) -# end -# end -# -# it "should return a status of 202" do -# mnode = stub("Node", :null_object => true) -# Chef::FileStore.stub!(:load).with("node", "one").and_return(mnode) -# Chef::FileStore.stub!(:delete) -# controller = do_destroy -# controller.status.should eql(202) -# end -# end -# -# describe Nodes, "compile action" do -# before(:each) do -# @compile = stub("Compile", :null_object => true) -# @node = stub("Node", :null_object => true) -# @node.stub!(:[]).and_return(true) -# @node.stub!(:[]=).and_return(true) -# @node.stub!(:recipes).and_return([]) -# @compile.stub!(:load_definitions).and_return(true) -# @compile.stub!(:load_recipes).and_return(true) -# @compile.stub!(:collection).and_return([]) -# @compile.stub!(:node, @node) -# @compile.stub!(:load_node).and_return(true) -# @stored_node = stub("Stored Node", :null_object => true) -# end -# -# def do_compile -# Chef::FileStore.stub!(:store).and_return(true) -# Chef::FileStore.stub!(:load).and_return(@stored_node) -# Chef::Compile.stub!(:new).and_return(@compile) -# dispatch_to(Nodes, :compile, { :id => "one" }) do |c| -# c.stub!(:display) -# end -# end -# -# it "should load the node from the node resource" do -# @compile.should_receive(:load_node).with("one").and_return(true) -# do_compile -# end -# -# it "should merge the data with the currently stored node" do -# node1 = Chef::Node.new -# node1.name "adam" -# node1.music "crowe" -# node1.recipes << "monkey" -# @compile.stub!(:node).and_return(node1) -# @stored_node = Chef::Node.new -# @stored_node.name "adam" -# @stored_node.music "crown" -# @stored_node.woot "woot" -# @stored_node.recipes << "monkeysoup" -# do_compile -# node1.name.should eql("adam") -# node1.music.should eql("crown") -# node1.woot.should eql("woot") -# node1.recipes.should eql([ "monkey", "monkeysoup" ]) -# end -# -# it "should load definitions" do -# @compile.should_receive(:load_definitions) -# do_compile -# end -# -# it "should load recipes" do -# @compile.should_receive(:load_recipes) -# do_compile -# end -# -# it "should display the collection and node object" do -# Chef::FileStore.stub!(:load).and_return(@stored_node) -# Chef::Compile.stub!(:new).and_return(@compile) -# dispatch_to(Nodes, :compile, { :id => "one" }) do |c| -# c.should_receive(:display).with({ :collection => [], :node => nil }) -# end -# end -# -# it "should return 200" do -# controller = do_compile -# controller.status.should eql(200) -# end -# -# end
\ No newline at end of file diff --git a/spec/chef_server/controllers/openid_consumer_spec.rb b/spec/chef_server/controllers/openid_consumer_spec.rb deleted file mode 100644 index 0156fd8d49..0000000000 --- a/spec/chef_server/controllers/openid_consumer_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.join(File.dirname(__FILE__), "..", 'spec_helper.rb') -# -# describe OpenidConsumer, "check_valid_openid_provider method" do -# it "should confirm the openid provider if the openid_providers config is nil" do -# Chef::Config[:openid_providers] = nil -# c = OpenidConsumer.new(true) -# c.send(:check_valid_openid_provider, "monkeyid").should eql(true) -# end -# -# it "should return true if the openid provider is in openid_providers list" do -# Chef::Config[:openid_providers] = [ 'monkeyid' ] -# c = OpenidConsumer.new(true) -# c.send(:check_valid_openid_provider, "monkeyid").should eql(true) -# end -# -# it "should return true if the openid provider is in openid_providers list with http://" do -# Chef::Config[:openid_providers] = [ 'monkeyid' ] -# c = OpenidConsumer.new(true) -# c.send(:check_valid_openid_provider, "http://monkeyid").should eql(true) -# end -# -# it "should raise an exception if the openid provider is not in openid_providers list" do -# Chef::Config[:openid_providers] = [ 'monkeyid' ] -# c = OpenidConsumer.new(true) -# lambda { -# c.send(:check_valid_openid_provider, "monkey") -# }.should raise_error(Merb::Controller::Unauthorized) -# end -# end
\ No newline at end of file diff --git a/spec/chef_server/controllers/openid_register_spec.rb b/spec/chef_server/controllers/openid_register_spec.rb deleted file mode 100644 index c883715fc6..0000000000 --- a/spec/chef_server/controllers/openid_register_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.join(File.dirname(__FILE__), "..", 'spec_helper.rb') -# -# describe OpenidRegister, "index action" do -# it "should get a list of all registered nodes" do -# Chef::OpenIDRegistration.should_receive(:list).with(true).and_return(["one"]) -# dispatch_to(OpenidRegister, :index) do |c| -# c.stub!(:display) -# end -# end -# end -# -# describe OpenidRegister, "show action" do -# it "should raise a 404 if the nodes registration is not found" do -# Chef::OpenIDRegistration.should_receive(:load).with("foo").and_raise(RuntimeError) -# lambda { -# dispatch_to(OpenidRegister, :show, { :id => "foo" }) -# }.should raise_error(Merb::ControllerExceptions::NotFound) -# end -# -# it "should call display on the node registration" do -# Chef::OpenIDRegistration.stub!(:load).and_return(true) -# dispatch_to(OpenidRegister, :show, { :id => "foo" }) do |c| -# c.should_receive(:display).with(true) -# end -# end -# end -# -# describe OpenidRegister, "create action" do -# def do_create -# dispatch_to(OpenidRegister, :create, { :id => "foo", :password => "beck" }) do |c| -# c.stub!(:display) -# end -# end -# -# it "should require an id to register" do -# lambda { -# dispatch_to(OpenidRegister, :create, { :password => "beck" }) -# }.should raise_error(Merb::ControllerExceptions::BadRequest) -# end -# -# it "should require a password to register" do -# lambda { -# dispatch_to(OpenidRegister, :create, { :id => "foo" }) -# }.should raise_error(Merb::ControllerExceptions::BadRequest) -# end -# -# it "should return 400 if a node is already registered" do -# Chef::OpenIDRegistration.should_receive(:has_key?).with("foo").and_return(true) -# lambda { -# dispatch_to(OpenidRegister, :create, { :id => "foo", :password => "beck" }) -# }.should raise_error(Merb::ControllerExceptions::BadRequest) -# end -# -# it "should store the registration in a new Chef::OpenIDRegistration" do -# mock_reg = mock("Chef::OpenIDRegistration", :null_object => true) -# mock_reg.should_receive(:name=).with("foo").and_return(true) -# mock_reg.should_receive(:set_password).with("beck").and_return(true) -# mock_reg.should_receive(:save).and_return(true) -# Chef::OpenIDRegistration.stub!(:has_key?).and_return(false) -# Chef::OpenIDRegistration.should_receive(:new).and_return(mock_reg) -# do_create -# end -# end -# -# describe OpenidRegister, "update action" do -# it "should raise a 400 error" do -# lambda { -# dispatch_to(OpenidRegister, :update) -# } -# end -# end -# -# describe OpenidRegister, "destroy action" do -# def do_destroy -# dispatch_to(OpenidRegister, :destroy, { :id => "foo" }) do |c| -# c.stub!(:display) -# end -# end -# -# it "should return 400 if it cannot find the registration" do -# Chef::OpenIDRegistration.should_receive(:load).and_raise(ArgumentError) -# lambda { -# do_destroy -# }.should raise_error(Merb::ControllerExceptions::BadRequest) -# end -# -# it "should delete the registration from the store" do -# mock_reg = mock("OpenIDRegistration") -# mock_reg.should_receive(:destroy).and_return(true) -# Chef::OpenIDRegistration.should_receive(:load).with("foo").and_return(mock_reg) -# do_destroy -# end -# end
\ No newline at end of file diff --git a/spec/chef_server/log/merb_test.log b/spec/chef_server/log/merb_test.log deleted file mode 100644 index b2aa15df9a..0000000000 --- a/spec/chef_server/log/merb_test.log +++ /dev/null @@ -1,4 +0,0 @@ -Mon, 16 Jun 2008 02:08:02 GMT ~ info ~ Logfile created - ~ Not Using Sessions - ~ Not Using Sessions - ~ Not Using Sessions diff --git a/spec/chef_server/spec.opts b/spec/chef_server/spec.opts deleted file mode 100644 index 3a2ff550a2..0000000000 --- a/spec/chef_server/spec.opts +++ /dev/null @@ -1,4 +0,0 @@ ---color ---loadby -mtime - diff --git a/spec/chef_server/spec_helper.rb b/spec/chef_server/spec_helper.rb deleted file mode 100644 index 90c1e0af7a..0000000000 --- a/spec/chef_server/spec_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rubygems' -require 'merb-core' -require 'spec' # Satiates Autotest and anyone else not using the Rake tasks - -Merb.start_environment( - :testing => true, - :adapter => 'runner', - :environment => ENV['MERB_ENV'] || 'test', - :init_file => File.join(File.dirname(__FILE__), "..", "..", "lib", "chef_server", "init.rb") -) - -Spec::Runner.configure do |config| - config.include(Merb::Test::ViewHelper) - config.include(Merb::Test::RouteHelper) - config.include(Merb::Test::ControllerHelper) -end diff --git a/spec/data/bad-config.rb b/spec/data/bad-config.rb deleted file mode 100644 index 5477a69366..0000000000 --- a/spec/data/bad-config.rb +++ /dev/null @@ -1 +0,0 @@ -monkey_soup("tastes nice")
\ No newline at end of file diff --git a/spec/data/compile/cookbooks/test/attributes/george.rb b/spec/data/compile/cookbooks/test/attributes/george.rb deleted file mode 100644 index 5df9567761..0000000000 --- a/spec/data/compile/cookbooks/test/attributes/george.rb +++ /dev/null @@ -1 +0,0 @@ -george "washington"
\ No newline at end of file diff --git a/spec/data/compile/cookbooks/test/definitions/new_cat.rb b/spec/data/compile/cookbooks/test/definitions/new_cat.rb deleted file mode 100644 index a49b53348c..0000000000 --- a/spec/data/compile/cookbooks/test/definitions/new_cat.rb +++ /dev/null @@ -1,5 +0,0 @@ -define :new_cat, :is_pretty => true do - cat "#{params[:name]}" do - pretty_kitty params[:is_pretty] - end -end diff --git a/spec/data/compile/cookbooks/test/recipes/default.rb b/spec/data/compile/cookbooks/test/recipes/default.rb deleted file mode 100644 index d769dc826d..0000000000 --- a/spec/data/compile/cookbooks/test/recipes/default.rb +++ /dev/null @@ -1,5 +0,0 @@ - -cat "einstein" do - pretty_kitty true -end - diff --git a/spec/data/compile/cookbooks/test/recipes/one.rb b/spec/data/compile/cookbooks/test/recipes/one.rb deleted file mode 100644 index 7795cc1d4a..0000000000 --- a/spec/data/compile/cookbooks/test/recipes/one.rb +++ /dev/null @@ -1,7 +0,0 @@ -cat "loulou" do - pretty_kitty true -end - -new_cat "birthday" do - pretty_kitty false -end diff --git a/spec/data/compile/cookbooks/test/recipes/two.rb b/spec/data/compile/cookbooks/test/recipes/two.rb deleted file mode 100644 index 01def1b2ac..0000000000 --- a/spec/data/compile/cookbooks/test/recipes/two.rb +++ /dev/null @@ -1,7 +0,0 @@ -cat "peanut" do - pretty_kitty true -end - -new_cat "fat peanut" do - pretty_kitty false -end diff --git a/spec/data/compile/nodes/compile.rb b/spec/data/compile/nodes/compile.rb deleted file mode 100644 index 84d52bb1cf..0000000000 --- a/spec/data/compile/nodes/compile.rb +++ /dev/null @@ -1,5 +0,0 @@ -## -# Nodes should have a unique name -## -name "compile" -recipes "test", "test::one", "test::two" diff --git a/spec/data/config.rb b/spec/data/config.rb deleted file mode 100644 index 0b3340ce57..0000000000 --- a/spec/data/config.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Sample Chef Config File -# - -cookbook_path "/etc/chef/cookbook", "/etc/chef/site-cookbook" - diff --git a/spec/data/cookbooks/openldap/attributes/default.rb b/spec/data/cookbooks/openldap/attributes/default.rb deleted file mode 100644 index 204ae9ed77..0000000000 --- a/spec/data/cookbooks/openldap/attributes/default.rb +++ /dev/null @@ -1,15 +0,0 @@ -chef_env ||= nil -case chef_env -when "prod" - ldap_server "ops1prod" - ldap_basedn "dc=hjksolutions,dc=com" - ldap_replication_password "yes" -when "corp" - ldap_server "ops1prod" - ldap_basedn "dc=hjksolutions,dc=com" - 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 deleted file mode 100644 index 63f5b56c7f..0000000000 --- a/spec/data/cookbooks/openldap/attributes/smokey.rb +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index ac81831d11..0000000000 --- a/spec/data/cookbooks/openldap/definitions/client.rb +++ /dev/null @@ -1,5 +0,0 @@ -define :openldap_client, :mothra => "a big monster" do - cat "#{params[: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 deleted file mode 100644 index 2df437aa84..0000000000 --- a/spec/data/cookbooks/openldap/definitions/server.rb +++ /dev/null @@ -1,5 +0,0 @@ -define :openldap_server, :mothra => "a big monster" do - cat "#{params[:name]}" do - pretty_kitty true - end -end diff --git a/spec/data/cookbooks/openldap/ignore b/spec/data/cookbooks/openldap/ignore deleted file mode 100644 index e96f4e7df4..0000000000 --- a/spec/data/cookbooks/openldap/ignore +++ /dev/null @@ -1,6 +0,0 @@ -# -# The ignore file allows you to skip files in cookbooks with the same name that appear -# later in the search path. -# - -recipes/ignoreme.rb
\ No newline at end of file diff --git a/spec/data/cookbooks/openldap/recipes/default.rb b/spec/data/cookbooks/openldap/recipes/default.rb deleted file mode 100644 index 0ac8a9bb4b..0000000000 --- a/spec/data/cookbooks/openldap/recipes/default.rb +++ /dev/null @@ -1,3 +0,0 @@ -cat "blanket" do - pretty_kitty true -end diff --git a/spec/data/cookbooks/openldap/recipes/gigantor.rb b/spec/data/cookbooks/openldap/recipes/gigantor.rb deleted file mode 100644 index b450eca7cd..0000000000 --- a/spec/data/cookbooks/openldap/recipes/gigantor.rb +++ /dev/null @@ -1,3 +0,0 @@ -cat "blanket" do - pretty_kitty false -end diff --git a/spec/data/cookbooks/openldap/recipes/one.rb b/spec/data/cookbooks/openldap/recipes/one.rb deleted file mode 100644 index e1c3cff92e..0000000000 --- a/spec/data/cookbooks/openldap/recipes/one.rb +++ /dev/null @@ -1,15 +0,0 @@ -## -# Nodes should have a unique name -## -name "test.example.com default" - -## -# Nodes can set arbitrary arguments -## -sunshine "in" -something "else" - -## -# Nodes should have recipes -## -recipes "operations-master", "operations-monitoring" diff --git a/spec/data/cookbooks/openldap/templates/default/test.erb b/spec/data/cookbooks/openldap/templates/default/test.erb deleted file mode 100644 index f39fa7da89..0000000000 --- a/spec/data/cookbooks/openldap/templates/default/test.erb +++ /dev/null @@ -1 +0,0 @@ -We could be diving for pearls! diff --git a/spec/data/definitions/test.rb b/spec/data/definitions/test.rb deleted file mode 100644 index b0d0effc27..0000000000 --- a/spec/data/definitions/test.rb +++ /dev/null @@ -1,5 +0,0 @@ -define :rico_suave, :rich => "smooth" do - zen_master "test" do - something "#{params[:rich]}" - end -end
\ No newline at end of file diff --git a/spec/data/kitchen/openldap/attributes/default.rb b/spec/data/kitchen/openldap/attributes/default.rb deleted file mode 100644 index d208959475..0000000000 --- a/spec/data/kitchen/openldap/attributes/default.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# Nothing to see here, move along -# diff --git a/spec/data/kitchen/openldap/attributes/robinson.rb b/spec/data/kitchen/openldap/attributes/robinson.rb deleted file mode 100644 index 9d6b44d464..0000000000 --- a/spec/data/kitchen/openldap/attributes/robinson.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# Smokey lives here -#
\ No newline at end of file diff --git a/spec/data/kitchen/openldap/definitions/client.rb b/spec/data/kitchen/openldap/definitions/client.rb deleted file mode 100644 index d4c2263b54..0000000000 --- a/spec/data/kitchen/openldap/definitions/client.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# A sad client -# diff --git a/spec/data/kitchen/openldap/definitions/drewbarrymore.rb b/spec/data/kitchen/openldap/definitions/drewbarrymore.rb deleted file mode 100644 index 510f0c35da..0000000000 --- a/spec/data/kitchen/openldap/definitions/drewbarrymore.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# Was in people magazine this month... -#
\ No newline at end of file diff --git a/spec/data/kitchen/openldap/recipes/gigantor.rb b/spec/data/kitchen/openldap/recipes/gigantor.rb deleted file mode 100644 index 70a41960eb..0000000000 --- a/spec/data/kitchen/openldap/recipes/gigantor.rb +++ /dev/null @@ -1,3 +0,0 @@ -cat "blanket" do - pretty_kitty true -end
\ No newline at end of file diff --git a/spec/data/kitchen/openldap/recipes/ignoreme.rb b/spec/data/kitchen/openldap/recipes/ignoreme.rb deleted file mode 100644 index 15095986c6..0000000000 --- a/spec/data/kitchen/openldap/recipes/ignoreme.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# this file will never be seen -#
\ No newline at end of file diff --git a/spec/data/kitchen/openldap/recipes/woot.rb b/spec/data/kitchen/openldap/recipes/woot.rb deleted file mode 100644 index 44893dae36..0000000000 --- a/spec/data/kitchen/openldap/recipes/woot.rb +++ /dev/null @@ -1,3 +0,0 @@ -# -# Such a funny word.. -# diff --git a/spec/data/nodes/default.rb b/spec/data/nodes/default.rb deleted file mode 100644 index e1c3cff92e..0000000000 --- a/spec/data/nodes/default.rb +++ /dev/null @@ -1,15 +0,0 @@ -## -# Nodes should have a unique name -## -name "test.example.com default" - -## -# Nodes can set arbitrary arguments -## -sunshine "in" -something "else" - -## -# Nodes should have recipes -## -recipes "operations-master", "operations-monitoring" diff --git a/spec/data/nodes/test.example.com.rb b/spec/data/nodes/test.example.com.rb deleted file mode 100644 index 9c374395bf..0000000000 --- a/spec/data/nodes/test.example.com.rb +++ /dev/null @@ -1,15 +0,0 @@ -## -# Nodes should have a unique name -## -name "test.example.com" - -## -# Nodes can set arbitrary arguments -## -sunshine "in" -something "else" - -## -# Nodes should have recipes -## -recipes "operations-master", "operations-monitoring" diff --git a/spec/data/nodes/test.rb b/spec/data/nodes/test.rb deleted file mode 100644 index d968816d60..0000000000 --- a/spec/data/nodes/test.rb +++ /dev/null @@ -1,15 +0,0 @@ -## -# Nodes should have a unique name -## -name "test.example.com short" - -## -# Nodes can set arbitrary arguments -## -sunshine "in" -something "else" - -## -# Nodes should have recipes -## -recipes "operations-master", "operations-monitoring" diff --git a/spec/data/recipes/test.rb b/spec/data/recipes/test.rb deleted file mode 100644 index 1c94b917f0..0000000000 --- a/spec/data/recipes/test.rb +++ /dev/null @@ -1,7 +0,0 @@ - -file "/etc/nsswitch.conf" do - action "create" - owner "root" - group "root" - mode 0644 -end diff --git a/spec/data/seattle.txt b/spec/data/seattle.txt deleted file mode 100644 index 19f6290939..0000000000 --- a/spec/data/seattle.txt +++ /dev/null @@ -1 +0,0 @@ -Seattle is a great town. Next time you visit, you should buy me a beer.
\ No newline at end of file diff --git a/spec/lib/chef/provider/easy.rb b/spec/lib/chef/provider/easy.rb deleted file mode 100644 index b637efa768..0000000000 --- a/spec/lib/chef/provider/easy.rb +++ /dev/null @@ -1,37 +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 -# - -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 deleted file mode 100644 index 0486402686..0000000000 --- a/spec/lib/chef/provider/snakeoil.rb +++ /dev/null @@ -1,37 +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 -# - -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 deleted file mode 100644 index e651c44512..0000000000 --- a/spec/lib/chef/resource/cat.rb +++ /dev/null @@ -1,42 +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 -# - -class Chef - class Resource - class Cat < Chef::Resource - - attr_accessor :action - - def initialize(name, collection=nil, node=nil) - @resource_name = :cat - super(name, collection, node) - @action = "sell" - end - - def pretty_kitty(arg=nil) - set_if_args(@pretty_kitty, arg) do - case arg - when true, false - @pretty_kitty = arg - end - end - end - end - end -end
\ No newline at end of file diff --git a/spec/lib/chef/resource/zen_master.rb b/spec/lib/chef/resource/zen_master.rb deleted file mode 100644 index 8b4225fbd4..0000000000 --- a/spec/lib/chef/resource/zen_master.rb +++ /dev/null @@ -1,44 +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 -# - -class Chef - class Resource - class ZenMaster < Chef::Resource - attr_reader :peace - - def initialize(name, collection=nil, node=nil) - @resource_name = :zen_master - super(name, collection, node) - end - - def peace(tf) - @peace = tf - end - - def something(arg=nil) - set_if_args(@something, arg) do - case arg - when true, false - @something = arg - end - end - end - end - end -end
\ No newline at end of file diff --git a/spec/rcov.opts b/spec/rcov.opts deleted file mode 100644 index 484626ea9c..0000000000 --- a/spec/rcov.opts +++ /dev/null @@ -1,2 +0,0 @@ ---exclude -spec,bin,/Library/Ruby diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index c9c9b4ddf0..0000000000 --- a/spec/spec.opts +++ /dev/null @@ -1,3 +0,0 @@ ---color ---loadby -mtime diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 9120b2876c..0000000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,23 +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__), "..", "lib", "chef") -Dir[File.join(File.dirname(__FILE__), 'lib', '**', '*.rb')].sort.each { |lib| require lib } - -Chef::Config.log_level(:error) diff --git a/spec/unit/chef_spec.rb b/spec/unit/chef_spec.rb deleted file mode 100644 index 7d2af6f88d..0000000000 --- a/spec/unit/chef_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef do - it "should have a version defined" do - Chef::VERSION.should match(/(\d+)\.(\d+)\.(\d+)/) - end -end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb deleted file mode 100644 index a2732f28c3..0000000000 --- a/spec/unit/client_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Client, "initialize" do - it "should create a new Chef::Client object" do - Chef::Client.new.should be_kind_of(Chef::Client) - end -end - -describe Chef::Client, "build_node" do - before(:each) do - @mock_facter_fqdn = mock("Facter FQDN") - @mock_facter_fqdn.stub!(:value).and_return("foo.bar.com") - @mock_facter_hostname = mock("Facter Hostname") - @mock_facter_hostname.stub!(:value).and_return("foo") - Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn) - Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname) - Facter.stub!(:each).and_return(true) - @client = Chef::Client.new - end - - it "should set the name equal to the FQDN" do - @client.build_node - @client.node.name.should eql("foo.bar.com") - end - - it "should set the name equal to the hostname if FQDN is not available" do - @mock_facter_fqdn.stub!(:value).and_return(nil) - @client.build_node - @client.node.name.should eql("foo") - end -end - -describe Chef::Client, "register" do - before(:each) do - @client = Chef::Client.new - end - - it "should check to see if it's already registered" - - it "should create a new passphrase if not registered" - - it "should create a new registration if it has not registered" -end
\ No newline at end of file diff --git a/spec/unit/compile_spec.rb b/spec/unit/compile_spec.rb deleted file mode 100644 index c7f76a4a58..0000000000 --- a/spec/unit/compile_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Compile do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "compile", "nodes")) - Chef::Config.cookbook_path(File.join(File.dirname(__FILE__), "..", "data", "compile", "cookbooks")) - @compile = Chef::Compile.new - end - - it "should create a new Chef::Compile" do - @compile.should be_a_kind_of(Chef::Compile) - end - - it "should have a Chef::CookbookLoader" do - @compile.cookbook_loader.should be_a_kind_of(Chef::CookbookLoader) - end - - it "should have a Chef::ResourceCollection" do - @compile.collection.should be_a_kind_of(Chef::ResourceCollection) - end - - it "should have a hash of Definitions" do - @compile.definitions.should be_a_kind_of(Hash) - end - - it "should load a node by name" do - node = Chef::Node.new - Chef::Node.stub!(:load).and_return(node) - lambda { - @compile.load_node("compile") - }.should_not raise_error - @compile.node.name.should == "compile" - end - - it "should load all the definitions" do - lambda { @compile.load_definitions }.should_not raise_error - @compile.definitions.should have_key(:new_cat) - end - - it "should load all the recipes specified for this node" do - node = Chef::Node.new - Chef::Node.stub!(:load).and_return(node) - @compile.load_node("compile") - @compile.load_definitions - lambda { @compile.load_recipes }.should_not raise_error - @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/config_spec.rb b/spec/unit/config_spec.rb deleted file mode 100644 index 51e33401d8..0000000000 --- a/spec/unit/config_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Config do - - it "should load a .rb file in context" do - lambda { - Chef::Config.from_file(File.join(File.dirname(__FILE__), "..", "data", "config.rb")) - }.should_not raise_error - end - - it "should raise an ArgumentError with an explanation if you try and set a non-existent variable" do - lambda { - Chef::Config.from_file(File.join(File.dirname(__FILE__), "..", "data", "bad-config.rb")) - }.should raise_error(ArgumentError) - end - - it "should raise an IOError if it can't find the file" do - lambda { - Chef::Config.from_file("/tmp/timmytimmytimmy") - }.should raise_error(IOError) - end - - it "should have a default cookbook_path" do - Chef::Config.cookbook_path.should be_kind_of(Array) - end - - it "should allow you to set a cookbook_path with a string" do - Chef::Config.cookbook_path("/etc/chef/cookbook") - Chef::Config.cookbook_path.should eql("/etc/chef/cookbook") - end - - it "should allow you to set a cookbook_path with multiple strings" do - Chef::Config.cookbook_path("/etc/chef/cookbook", "/etc/chef/upstream-cookbooks") - Chef::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 - Chef::Config.cookbook_path ["one", "two"] - Chef::Config.cookbook_path.should eql(["one", "two"]) - end - - it "should allow you to reference a value by index" do - Chef::Config[:cookbook_path].should be_kind_of(Array) - end - - it "should allow you to set a value by index" do - Chef::Config[:cookbook_path] = "one" - Chef::Config[:cookbook_path].should == "one" - end - - it "should allow you to set config values with a block" do - Chef::Config.configure do |c| - c[:cookbook_path] = "monkey_rabbit" - c[:otherthing] = "boo" - end - Chef::Config.cookbook_path.should == "monkey_rabbit" - Chef::Config.otherthing.should == "boo" - end - - it "should raise an ArgumentError if you access a config option that does not exist" do - lambda { Chef::Config[:snob_hobbery] }.should raise_error(ArgumentError) - end - - it "should return true or false with has_key?" do - Chef::Config.has_key?(:monkey).should eql(false) - Chef::Config[:monkey] = "gotcha" - Chef::Config.has_key?(:monkey).should eql(true) - end - -end
\ No newline at end of file diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb deleted file mode 100644 index 501329777b..0000000000 --- a/spec/unit/cookbook_loader_spec.rb +++ /dev/null @@ -1,117 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::CookbookLoader do - before(:each) do - Chef::Config.cookbook_path [ - File.join(File.dirname(__FILE__), "..", "data", "cookbooks"), - File.join(File.dirname(__FILE__), "..", "data", "kitchen") - ] - @cl = Chef::CookbookLoader.new() - end - - it "should be a Chef::CookbookLoader object" do - @cl.should be_kind_of(Chef::CookbookLoader) - end - - it "should return cookbook objects with []" do - @cl[:openldap].should be_a_kind_of(Chef::Cookbook) - end - - it "should raise an exception if it cannot find a cookbook with []" do - lambda { @cl[:monkeypoop] }.should raise_error(ArgumentError) - end - - it "should allow you to look up available cookbooks with [] and a symbol" do - @cl[:openldap].name.should eql(:openldap) - end - - it "should allow you to look up available cookbooks with [] and a string" do - @cl["openldap"].name.should eql(:openldap) - end - - it "should allow you to iterate over cookbooks with each" do - seen = Hash.new - @cl.each do |cb| - seen[cb.name] = true - end - seen.should have_key(:openldap) - seen.should have_key(:apache2) - end - - it "should find all the cookbooks in the cookbook path" do - Chef::Config.cookbook_path << File.join(File.dirname(__FILE__), "..", "data", "hidden-cookbooks") - @cl.load_cookbooks - @cl.detect { |cb| cb.name == :openldap }.should_not eql(nil) - @cl.detect { |cb| cb.name == :apache2 }.should_not eql(nil) - end - - it "should allow you to override an attribute file via cookbook_path" do - @cl[:openldap].attribute_files.detect { |f| - f =~ /cookbooks\/openldap\/attributes\/default.rb/ - }.should_not eql(nil) - @cl[:openldap].attribute_files.detect { |f| - f =~ /kitchen\/openldap\/attributes\/default.rb/ - }.should eql(nil) - end - - it "should load different attribute files from deeper paths" do - @cl[:openldap].attribute_files.detect { |f| - f =~ /kitchen\/openldap\/attributes\/robinson.rb/ - }.should_not eql(nil) - end - - it "should allow you to override a definition file via cookbook_path" do - @cl[:openldap].definition_files.detect { |f| - f =~ /cookbooks\/openldap\/definitions\/client.rb/ - }.should_not eql(nil) - @cl[:openldap].definition_files.detect { |f| - f =~ /kitchen\/openldap\/definitions\/client.rb/ - }.should eql(nil) - end - - it "should load definition files from deeper paths" do - @cl[:openldap].definition_files.detect { |f| - f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/ - }.should_not eql(nil) - end - - it "should allow you to override a recipe file via cookbook_path" do - @cl[:openldap].recipe_files.detect { |f| - f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/ - }.should_not eql(nil) - @cl[:openldap].recipe_files.detect { |f| - f =~ /kitchen\/openldap\/recipes\/gigantor.rb/ - }.should eql(nil) - end - - it "should load recipe files from deeper paths" do - @cl[:openldap].recipe_files.detect { |f| - f =~ /kitchen\/openldap\/recipes\/woot.rb/ - }.should_not eql(nil) - end - - it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do - @cl[:openldap].recipe_files.detect { |f| - f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/ - }.should eql(nil) - end - -end
\ No newline at end of file diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb deleted file mode 100644 index 85b4040771..0000000000 --- a/spec/unit/cookbook_spec.rb +++ /dev/null @@ -1,142 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(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 - - it "should load the attributes if it has not already when a recipe is loaded" do - @cookbook.attribute_files = Dir[File.join(COOKBOOK_PATH, "attributes", "smokey.rb")] - @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) - node.smokey.should == "robinson" - end -end
\ No newline at end of file diff --git a/spec/unit/couchdb_spec.rb b/spec/unit/couchdb_spec.rb deleted file mode 100644 index 621439df51..0000000000 --- a/spec/unit/couchdb_spec.rb +++ /dev/null @@ -1,212 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::CouchDB, "new" do - it "should create a new Chef::REST object from the default url" do - Chef::Config[:couchdb_url] = "http://monkey" - Chef::REST.should_receive(:new).with("http://monkey").and_return(true) - Chef::CouchDB.new - end - - it "should create a new Chef::REST object from a provided url" do - Chef::REST.should_receive(:new).with("http://monkeypants").and_return(true) - Chef::CouchDB.new("http://monkeypants") - end -end - -describe Chef::CouchDB, "create_db" do - before(:each) do - @mock_rest = mock("Chef::REST", :null_object => true) - @mock_rest.stub!(:get_rest).and_return([ "chef" ]) - @mock_rest.stub!(:put_rest).and_return(true) - Chef::REST.stub!(:new).and_return(@mock_rest) - end - - def do_create_db - couch = Chef::CouchDB.new - couch.create_db - end - - it "should get a list of current databases" do - @mock_rest.should_receive(:get_rest).and_return(["chef"]) - do_create_db - end - - it "should create the chef database if it does not exist" do - @mock_rest.stub!(:get_rest).and_return([]) - @mock_rest.should_receive(:put_rest).with("chef", {}).and_return(true) - do_create_db - end - - it "should not create the chef database if it does exist" do - @mock_rest.stub!(:get_rest).and_return(["chef"]) - @mock_rest.should_not_receive(:put_rest) - do_create_db - end - - it "should return 'chef'" do - do_create_db.should eql("chef") - end -end - -describe Chef::CouchDB, "create_design_document" do - before(:each) do - @mock_rest = mock("Chef::REST", :null_object => true) - @mock_design = { - "version" => 1, - "_rev" => 1 - } - @mock_data = { - "version" => 1, - "language" => "javascript", - "views" => { - "all" => { - "map" => <<-EOJS - function(doc) { - if (doc.chef_type == "node") { - emit(doc.name, doc); - } - } - EOJS - }, - } - } - @mock_rest.stub!(:get_rest).and_return(@mock_design) - @mock_rest.stub!(:put_rest).and_return(true) - Chef::REST.stub!(:new).and_return(@mock_rest) - end - - def do_create_design_document - couchdb = Chef::CouchDB.new - couchdb.create_design_document("bob", @mock_data) - end - - it "should fetch the existing design document" do - @mock_rest.should_receive(:get_rest).with("chef/_design%2Fbob") - do_create_design_document - end - - it "should populate the _rev in the new design if the versions dont match" do - @mock_data["version"] = 2 - do_create_design_document - @mock_data["_rev"].should eql(1) - end - - it "should create the view if it requires updating" do - @mock_data["version"] = 2 - @mock_rest.should_receive(:put_rest).with("chef/_design%2Fbob", @mock_data) - do_create_design_document - end - - it "should not create the view if it does not require updating" do - @mock_data["version"] = 1 - @mock_rest.should_not_receive(:put_rest) - do_create_design_document - end -end - -describe Chef::CouchDB, "store" do - it "should put the object into couchdb" do - @mock_rest = mock("Chef::REST", :null_object => true) - @mock_rest.should_receive(:put_rest).with("chef/node_bob", {}).and_return(true) - Chef::REST.stub!(:new).and_return(@mock_rest) - Chef::CouchDB.new.store("node", "bob", {}) - end -end - -describe Chef::CouchDB, "load" do - it "should load the object from couchdb" do - @mock_rest = mock("Chef::REST", :null_object => true) - @mock_rest.should_receive(:get_rest).with("chef/node_bob").and_return(true) - Chef::REST.stub!(:new).and_return(@mock_rest) - Chef::CouchDB.new.load("node", "bob").should eql(true) - end -end - -describe Chef::CouchDB, "delete" do - before(:each) do - @mock_current = { - "version" => 1, - "_rev" => 1 - } - @mock_rest = mock("Chef::REST", :null_object => true) - @mock_rest.stub!(:get_rest).and_return(@mock_current) - @mock_rest.stub!(:delete_rest).and_return(true) - Chef::REST.stub!(:new).and_return(@mock_rest) - end - - def do_delete(rev=nil) - Chef::REST.stub!(:new).and_return(@mock_rest) - Chef::CouchDB.new.delete("node", "bob", rev) - end - - it "should remove the object from couchdb with a specific revision" do - @mock_rest.should_receive(:delete_rest).with("chef/node_bob?rev=1") - do_delete(1) - end - - it "should remove the object from couchdb based on the couchdb_rev of the current obj" do - mock_real = mock("Inflated Object") - mock_real.stub!(:respond_to?).and_return(true) - mock_real.stub!(:couchdb_rev).and_return(2) - @mock_rest.should_receive(:get_rest).with("chef/node_bob").and_return(mock_real) - @mock_rest.should_receive(:delete_rest).with("chef/node_bob?rev=2") - do_delete - end - - it "should remove the object from couchdb based on the current objects rev" do - @mock_rest.should_receive(:delete_rest).with("chef/node_bob?rev=1") - do_delete - end -end - -describe Chef::CouchDB, "list" do - before(:each) do - @mock_rest = mock("Chef::REST", :null_object => true) - Chef::REST.stub!(:new).and_return(@mock_rest) - end - - it "should get the view for all objects if inflate is true" do - @mock_rest.should_receive(:get_rest).with("chef/_view/node/all").and_return(true) - Chef::CouchDB.new.list("node", true) - end - - it "should get the view for just the object id's if inflate is false" do - @mock_rest.should_receive(:get_rest).with("chef/_view/node/all_id").and_return(true) - Chef::CouchDB.new.list("node", false) - end -end - -describe Chef::CouchDB, "has_key?" do - before(:each) do - @mock_rest = mock("Chef::REST", :null_object => true) - Chef::REST.stub!(:new).and_return(@mock_rest) - end - - it "should return true if the object exists" do - @mock_rest.should_receive(:get_rest).and_return(true) - Chef::CouchDB.new.has_key?("node", "bob").should eql(true) - end - - it "should return false if the object does not exist" do - @mock_rest.should_receive(:get_rest).and_raise(ArgumentError) - Chef::CouchDB.new.has_key?("node", "bob").should eql(false) - end -end diff --git a/spec/unit/file_cache_spec.rb b/spec/unit/file_cache_spec.rb deleted file mode 100644 index c84eea376e..0000000000 --- a/spec/unit/file_cache_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::FileCache, "store method" do - before(:each) do - Chef::Config[:file_cache_path] = "/tmp/foo" - Dir.stub!(:mkdir).and_return(true) - File.stub!(:directory?).and_return(true) - @io = mock("IO", { :print => true, :close => true }) - File.stub!(:open).and_return(@io) - end - - it "should create the directories leading up to bang" do - File.stub!(:directory?).and_return(false) - Dir.should_receive(:mkdir).with("/tmp").and_return(true) - Dir.should_receive(:mkdir).with("/tmp/foo").and_return(true) - Dir.should_receive(:mkdir).with("/tmp/foo/whiz").and_return(true) - Dir.should_not_receive(:mkdir).with("/tmp/foo/whiz/bang").and_return(true) - Chef::FileCache.store("whiz/bang", "I found a poop") - end - - it "should create a file at /tmp/foo/whiz/bang" do - File.should_receive(:open).with("/tmp/foo/whiz/bang", "w").and_return(@io) - Chef::FileCache.store("whiz/bang", "I found a poop") - end - - it "should print the contents to the file" do - @io.should_receive(:print).with("I found a poop") - Chef::FileCache.store("whiz/bang", "I found a poop") - end - - it "should close the file" do - @io.should_receive(:close) - Chef::FileCache.store("whiz/bang", "I found a poop") - end - -end - -describe Chef::FileCache, "load method" do - before(:each) do - Chef::Config[:file_cache_path] = "/tmp/foo" - Dir.stub!(:mkdir).and_return(true) - File.stub!(:directory?).and_return(true) - File.stub!(:exists?).and_return(true) - File.stub!(:read).and_return("I found a poop") - end - - it "should find the full path to whiz/bang" do - File.should_receive(:read).with("/tmp/foo/whiz/bang").and_return(true) - Chef::FileCache.load('whiz/bang') - end - - it "should raise a Chef::Exception::FileNotFound if the file doesn't exist" do - File.stub!(:exists?).and_return(false) - lambda { Chef::FileCache.load('whiz/bang') }.should raise_error(Chef::Exception::FileNotFound) - end -end - -describe Chef::FileCache, "delete method" do - before(:each) do - Chef::Config[:file_cache_path] = "/tmp/foo" - Dir.stub!(:mkdir).and_return(true) - File.stub!(:directory?).and_return(true) - File.stub!(:exists?).and_return(true) - File.stub!(:unlink).and_return(true) - end - - it "should unlink the full path to whiz/bang" do - File.should_receive(:unlink).with("/tmp/foo/whiz/bang").and_return(true) - Chef::FileCache.delete("whiz/bang") - end - -end - -describe Chef::FileCache, "list method" do - before(:each) do - Chef::Config[:file_cache_path] = "/tmp/foo" - Dir.stub!(:[]).and_return(["/tmp/foo/whiz/bang", "/tmp/foo/snappy/patter"]) - File.stub!(:file?).and_return(true) - end - - it "should return the relative paths" do - Chef::FileCache.list.should eql([ "whiz/bang", "snappy/patter" ]) - end -end - -describe Chef::FileCache, "has_key? method" do - before(:each) do - Chef::Config[:file_cache_path] = "/tmp/foo" - end - - it "should check the full path to the file" do - File.should_receive(:exists?).with("/tmp/foo/whiz/bang") - Chef::FileCache.has_key?("whiz/bang") - end - - it "should return true if the file exists" do - File.stub!(:exists?).and_return(true) - Chef::FileCache.has_key?("whiz/bang").should eql(true) - end - - it "should return false if the file does not exist" do - File.stub!(:exists?).and_return(false) - Chef::FileCache.has_key?("whiz/bang").should eql(false) - end -end - diff --git a/spec/unit/file_store_spec.rb b/spec/unit/file_store_spec.rb deleted file mode 100644 index 8addeb9e31..0000000000 --- a/spec/unit/file_store_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -class Fakestore - attr_accessor :name - - def to_json(*a) - { :name => @name }.to_json(*a) - end - - def self.json_create(o) - new_fakestore = new - new_fakestore.name = o[:name] - new_fakestore - end -end - -describe Chef::FileStore do - before(:each) do - Chef::Config[:file_store_path] = "/tmp/chef-test" - @fakestore = Fakestore.new - @fakestore.name = "Landslide" - @fakestore_digest = "a56a428bddac69e505731708ba206da0bb75e8de883bb4d5ef6be9b327da556a" - end - - it "should return a path to a file given a type and key" do - Dir.stub!(:mkdir).and_return(true) - File.stub!(:directory?).and_return(true) - path = Chef::FileStore.create_store_path("fakestore", @fakestore.name) - path.should eql("/tmp/chef-test/fakestore/a/56a/Landslide") - end - - it "should create directories for the path if needed" do - File.stub!(:directory?).and_return(false) - Dir.should_receive(:mkdir).exactly(4).times.and_return(true) - Chef::FileStore.create_store_path("fakestore", @fakestore.name) - end - - it "should store an object with a type and key" do - Chef::FileStore.should_receive(:create_store_path).with("fakestore", @fakestore.name).and_return("/monkey") - File.stub!(:directory?).and_return(true) - ioobj = mock("IO", :null_object => true) - ioobj.should_receive(:puts).with(@fakestore.to_json) - ioobj.should_receive(:close).once.and_return(true) - File.should_receive(:open).with("/monkey", "w").and_return(ioobj) - Chef::FileStore.store("fakestore", @fakestore.name, @fakestore) - end - - it "should load an object from the store with type and key" do - Chef::FileStore.should_receive(:create_store_path).with("fakestore", @fakestore.name).and_return("/monkey") - File.stub!(:exists?).and_return(true) - IO.should_receive(:read).once.and_return(true) - JSON.should_receive(:parse).and_return(true) - Chef::FileStore.load("fakestore", @fakestore.name) - end - - it "should through an exception if it cannot load a file from the store" do - Chef::FileStore.should_receive(:create_store_path).and_return("/tmp") - File.stub!(:exists?).and_return(false) - lambda { Chef::FileStore.load("fakestore", @fakestore.name) }.should raise_error(RuntimeError) - end - - it "should delete a file from the store if it exists" do - Chef::FileStore.should_receive(:create_store_path).with("node", "nothing").and_return("/tmp/foolio") - File.stub!(:exists?).and_return(true) - File.should_receive(:unlink).with("/tmp/foolio").and_return(1) - Chef::FileStore.delete("node", "nothing") - end - - it "should list all the keys of a particular type" do - Dir.should_receive(:[]).with("/tmp/chef-test/node/**/*").and_return(["pool"]) - File.should_receive(:file?).with("pool").and_return(true) - Chef::FileStore.list("node").should eql(["pool"]) - end - - it "should return all the documents of a particular type with list and inflate" do - Dir.stub!(:[]).and_return(["/foo/pool"]) - File.stub!(:file?).and_return(true) - Chef::FileStore.should_receive(:load).with("node", "pool").and_return("monkey") - Chef::FileStore.list("node", true).should eql(["monkey"]) - end - - it "should let you test whether a key doesnt exist for an object type with has_key?" do - Dir.should_receive(:[]).with("/tmp/chef-test/node/**/*").and_return(["pool"]) - File.should_receive(:file?).with("pool").and_return(true) - Chef::FileStore.has_key?("node", "snake").should eql(false) - end -end
\ No newline at end of file diff --git a/spec/unit/log/formatter_spec.rb b/spec/unit/log/formatter_spec.rb deleted file mode 100644 index e0d8bfd773..0000000000 --- a/spec/unit/log/formatter_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 'time' -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Log::Formatter do - before(:each) do - @formatter = Chef::Log::Formatter.new - end - - it "should print raw strings with msg2str(string)" do - @formatter.msg2str("nuthin new").should == "nuthin new" - end - - it "should format exceptions properly with msg2str(e)" do - e = IOError.new("legendary roots crew") - @formatter.msg2str(e).should == "legendary roots crew (IOError)\n" - end - - it "should format random objects via inspect with msg2str(Object)" do - @formatter.msg2str([ "black thought", "?uestlove" ]).should == '["black thought", "?uestlove"]' - end - - it "should return a formatted string with call" do - time = Time.new - Chef::Log::Formatter.show_time = true - @formatter.call("monkey", time, "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/log_spec.rb b/spec/unit/log_spec.rb deleted file mode 100644 index 14892b1af4..0000000000 --- a/spec/unit/log_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 'tempfile' -require 'logger' -require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Log do - it "should accept regular options to Logger.new via init" do - tf = Tempfile.new("chef-test-log") - tf.open - lambda { Chef::Log.init(STDOUT) }.should_not raise_error - lambda { Chef::Log.init(tf) }.should_not raise_error - end - - it "should set the log level with :debug, :info, :warn, :error, or :fatal" do - levels = { - :debug => Logger::DEBUG, - :info => Logger::INFO, - :warn => Logger::WARN, - :error => Logger::ERROR, - :fatal => Logger::FATAL - } - levels.each do |symbol, constant| - Chef::Log.level(symbol) - Chef::Log.logger.level.should == constant - end - end - - it "should raise an ArgumentError if you try and set the level to something strange" do - lambda { Chef::Log.level(:the_roots) }.should raise_error(ArgumentError) - end - - it "should pass other method calls directly to logger" do - Chef::Log.level(:debug) - Chef::Log.should be_debug - lambda { Chef::Log.debug("Gimme some sugar!") }.should_not raise_error - end - - it "should default to STDOUT if init is called with no arguments" do - logger_mock = mock(Logger, :null_object => true) - Logger.stub!(:new).and_return(logger_mock) - Logger.should_receive(:new).with(STDOUT).and_return(logger_mock) - Chef::Log.init - 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 deleted file mode 100644 index 937589b059..0000000000 --- a/spec/unit/mixin/params_validate_spec.rb +++ /dev/null @@ -1,331 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -class TinyClass - include Chef::Mixin::ParamsValidate - - def music(is_good=true) - is_good - end -end - -describe Chef::Mixin::ParamsValidate do - before(:each) do - @vo = TinyClass.new() - end - - it "should allow a hash and a hash as arguments to validate" do - lambda { @vo.validate({:one => "two"}, {}) }.should_not raise_error(ArgumentError) - end - - it "should raise an argument error if validate is called incorrectly" do - lambda { @vo.validate("one", "two") }.should raise_error(ArgumentError) - end - - it "should require validation map keys to be symbols or strings" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error(ArgumentError) - lambda { @vo.validate({:one => "two"}, { "one" => true }) }.should_not raise_error(ArgumentError) - lambda { @vo.validate({:one => "two"}, { Hash.new => true }) }.should raise_error(ArgumentError) - end - - it "should allow options to be required with true" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error(ArgumentError) - end - - it "should allow options to be optional with false" do - lambda { @vo.validate({}, {:one => false})}.should_not raise_error(ArgumentError) - end - - it "should allow you to check what kind_of? thing an argument is with kind_of" do - lambda { - @vo.validate( - {:one => "string"}, - { - :one => { - :kind_of => String - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - {:one => "string"}, - { - :one => { - :kind_of => Array - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should allow you to specify an argument is required with required" do - lambda { - @vo.validate( - {:one => "string"}, - { - :one => { - :required => true - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - {:two => "string"}, - { - :one => { - :required => true - } - } - ) - }.should raise_error(ArgumentError) - - lambda { - @vo.validate( - {:two => "string"}, - { - :one => { - :required => false - } - } - ) - }.should_not raise_error(ArgumentError) - end - - it "should allow you to specify whether an object has a method with respond_to" do - lambda { - @vo.validate( - {:one => @vo}, - { - :one => { - :respond_to => "validate" - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - {:one => @vo}, - { - :one => { - :respond_to => "monkey" - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should allow you to specify whether an object has all the given methods with respond_to and an array" do - lambda { - @vo.validate( - {:one => @vo}, - { - :one => { - :respond_to => ["validate", "music"] - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - {:one => @vo}, - { - :one => { - :respond_to => ["monkey", "validate"] - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should let you set a default value with default => value" do - arguments = Hash.new - @vo.validate(arguments, { - :one => { - :default => "is the loneliest number" - } - }) - arguments[:one].should == "is the loneliest number" - end - - it "should let you check regular expressions" do - lambda { - @vo.validate( - { :one => "is good" }, - { - :one => { - :regex => /^is good$/ - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - { :one => "is good" }, - { - :one => { - :regex => /^is bad$/ - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should let you specify your own callbacks" do - lambda { - @vo.validate( - { :one => "is good" }, - { - :one => { - :callbacks => { - "should be equal to is good" => lambda { |a| - a == "is good" - }, - } - } - } - ) - }.should_not raise_error(ArgumentError) - - lambda { - @vo.validate( - { :one => "is bad" }, - { - :one => { - :callbacks => { - "should be equal to 'is good'" => lambda { |a| - a == "is good" - }, - } - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should let you combine checks" do - args = { :one => "is good", :two => "is bad" } - lambda { - @vo.validate( - args, - { - :one => { - :kind_of => String, - :respond_to => [ :to_s, :upcase ], - :regex => /^is good/, - :callbacks => { - "should be your friend" => lambda { |a| - a == "is good" - } - }, - :required => true - }, - :two => { - :kind_of => String, - :required => false - }, - :three => { :default => "neato mosquito" } - } - ) - }.should_not raise_error(ArgumentError) - args[:three].should == "neato mosquito" - lambda { - @vo.validate( - args, - { - :one => { - :kind_of => String, - :respond_to => [ :to_s, :upcase ], - :regex => /^is good/, - :callbacks => { - "should be your friend" => lambda { |a| - a == "is good" - } - }, - :required => true - }, - :two => { - :kind_of => Hash, - :required => false - }, - :three => { :default => "neato mosquito" } - } - ) - }.should raise_error(ArgumentError) - end - - it "should raise an ArgumentError if the validation map has an unknown check" do - lambda { @vo.validate( - { :one => "two" }, - { - :one => { - :busted => "check" - } - } - ) - }.should raise_error(ArgumentError) - end - - it "should accept keys that are strings in the options" do - lambda { - @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/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb deleted file mode 100644 index 0ff929e8f6..0000000000 --- a/spec/unit/mixin/template_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -class TinyTemplateClass; include Chef::Mixin::Template; end - -describe Chef::Mixin::Template, "render_template" do - - before(:each) do - @template = "abcnews" - @context = { :fine => "dear" } - @eruby = mock(:erubis, { :evaluate => "elvis costello" }) - Erubis::Eruby.stub!(:new).and_return(@eruby) - @tempfile = mock(:tempfile, { :print => true, :close => true }) - Tempfile.stub!(:new).and_return(@tempfile) - @tiny_template = TinyTemplateClass.new - end - - it "should create a new Erubis object from the template" do - Erubis::Eruby.should_receive(:new).with("abcnews").and_return(@eruby) - @tiny_template.render_template(@template, @context) - end - - it "should evaluate the template with the provided context" do - @eruby.should_receive(:evaluate).with(@context).and_return(true) - @tiny_template.render_template(@template, @context) - end - - it "should create a tempfile for the resulting file" do - Tempfile.should_receive(:new).and_return(@tempfile) - @tiny_template.render_template(@template, @context) - end - - it "should print the contents of the resulting template to the tempfile" do - @tempfile.should_receive(:print).with("elvis costello").and_return(true) - @tiny_template.render_template(@template, @context) - end - - it "should close the tempfile" do - @tempfile.should_receive(:close).and_return(true) - @tiny_template.render_template(@template, @context) - end -end - diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb deleted file mode 100644 index 605bb8b628..0000000000 --- a/spec/unit/node_spec.rb +++ /dev/null @@ -1,326 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Node, "new method" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - end - - it "should create a new Chef::Node" do - @node.should be_a_kind_of(Chef::Node) - end -end - -describe Chef::Node, "name" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - 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 - -end - -describe Chef::Node, "attributes" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - 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 set an attribute via node[]=" do - @node["secret"] = "shush" - @node["secret"].should eql("shush") - 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 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 allow you to iterate over attributes with each_attribute" do - @node.sunshine "is bright" - @node.canada "is a nice place" - seen_attributes = Hash.new - @node.each_attribute do |a,v| - seen_attributes[a] = v - end - seen_attributes.should have_key(:sunshine) - seen_attributes.should have_key(:canada) - seen_attributes[:sunshine].should == "is bright" - seen_attributes[:canada].should == "is a nice place" - end - -end - -describe Chef::Node, "recipes" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - 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 - -end - -describe Chef::Node, "from file" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - 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("test.example.com short") - @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 - -describe Chef::Node, "find_file" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - end - - it "should load a node from a file by fqdn" do - @node.find_file("test.example.com") - @node.name.should == "test.example.com" - end - - it "should load a node from a file by hostname" do - File.stub!(:exists?).and_return(true) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) - @node.find_file("test.example.com") - @node.name.should == "test.example.com short" - end - - it "should load a node from the default file" do - File.stub!(:exists?).and_return(true) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false) - @node.find_file("test.example.com") - @node.name.should == "test.example.com default" - end - - it "should raise an ArgumentError if it cannot find any node file at all" do - File.stub!(:exists?).and_return(true) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false) - File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "default.rb")).and_return(false) - lambda { @node.find_file("test.example.com") }.should raise_error(ArgumentError) - end -end - -describe Chef::Node, "json" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - end - - it "should serialize itself as json" do - @node.find_file("test.example.com") - json = @node.to_json() - json.should =~ /json_class/ - json.should =~ /name/ - json.should =~ /attributes/ - json.should =~ /recipes/ - end - - it "should deserialize itself from json" do - @node.find_file("test.example.com") - json = @node.to_json - serialized_node = JSON.parse(json) - serialized_node.should be_a_kind_of(Chef::Node) - serialized_node.name.should eql(@node.name) - @node.each_attribute do |k,v| - serialized_node[k].should eql(v) - end - serialized_node.recipes.should eql(@node.recipes) - end -end - -describe Chef::Node, "to_index" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - @node.foo("bar") - end - - it "should return a hash with :index attributes" do - @node.name("airplane") - @node.to_index.should == { :foo => "bar", :index_name => "node", :id => "node_airplane", :name => "airplane" } - end -end - - -describe Chef::Node, "to_s" do - before(:each) do - Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) - @node = Chef::Node.new() - end - - it "should turn into a string like node[name]" do - @node.name("airplane") - @node.to_s.should eql("node[airplane]") - end -end - -describe Chef::Node, "list" do - before(:each) do - mock_couch = mock("Chef::CouchDB") - mock_couch.stub!(:list).and_return( - { - "rows" => [ - { - "value" => "a", - "key" => "avenue" - } - ] - } - ) - Chef::CouchDB.stub!(:new).and_return(mock_couch) - end - - it "should retrieve a list of nodes from CouchDB" do - Chef::Node.list.should eql(["avenue"]) - end - - it "should return just the ids if inflate is false" do - Chef::Node.list(false).should eql(["avenue"]) - end - - it "should return the full objects if inflate is true" do - Chef::Node.list(true).should eql(["a"]) - end -end - -describe Chef::Node, "load" do - it "should load a node from couchdb by name" do - mock_couch = mock("Chef::CouchDB") - mock_couch.should_receive(:load).with("node", "coffee").and_return(true) - Chef::CouchDB.stub!(:new).and_return(mock_couch) - Chef::Node.load("coffee") - end -end - -describe Chef::Node, "destroy" do - it "should delete this node from couchdb" do - mock_couch = mock("Chef::CouchDB") - mock_couch.should_receive(:delete).with("node", "bob", 1).and_return(true) - Chef::CouchDB.stub!(:new).and_return(mock_couch) - node = Chef::Node.new - node.name "bob" - node.couchdb_rev = 1 - Chef::Queue.should_receive(:send_msg).with(:queue, :remove, node) - node.destroy - end -end - -describe Chef::Node, "save" do - before(:each) do - @mock_couch = mock("Chef::CouchDB") - @mock_couch.stub!(:store).and_return({ "rev" => 33 }) - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - Chef::Queue.stub!(:send_msg).and_return(true) - @node = Chef::Node.new - @node.name "bob" - @node.couchdb_rev = 1 - end - - it "should save the node to couchdb" do - Chef::Queue.should_receive(:send_msg).with(:queue, :index, @node) - @mock_couch.should_receive(:store).with("node", "bob", @node).and_return({ "rev" => 33 }) - @node.save - end - - it "should store the new couchdb_rev" do - @node.save - @node.couchdb_rev.should eql(33) - end -end - -describe Chef::Node, "create_design_document" do - it "should create our design document" do - mock_couch = mock("Chef::CouchDB") - mock_couch.should_receive(:create_design_document).with("nodes", Chef::Node::DESIGN_DOCUMENT) - Chef::CouchDB.stub!(:new).and_return(mock_couch) - Chef::Node.create_design_document - end -end diff --git a/spec/unit/openid_registration_spec.rb b/spec/unit/openid_registration_spec.rb deleted file mode 100644 index d849369796..0000000000 --- a/spec/unit/openid_registration_spec.rb +++ /dev/null @@ -1,153 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::OpenIDRegistration, "initialize" do - it "should return a new Chef::OpenIDRegistration object" do - Chef::OpenIDRegistration.new.should be_kind_of(Chef::OpenIDRegistration) - end -end - -describe Chef::OpenIDRegistration, "set_password" do - it "should generate a salt for this object" do - oreg = Chef::OpenIDRegistration.new - oreg.salt.should eql(nil) - oreg.set_password("foolio") - oreg.salt.should_not eql(nil) - end - - it "should encrypt the password with the salt and the plaintext password" do - oreg = Chef::OpenIDRegistration.new - oreg.set_password("foolio") - oreg.password.should_not eql(nil) - end -end - -describe Chef::OpenIDRegistration, "to_json" do - it "should serialize itself as json" do - oreg = Chef::OpenIDRegistration.new - oreg.set_password("monkey") - json = oreg.to_json - %w{json_class chef_type name salt password validated}.each do |verify| - json.should =~ /#{verify}/ - end - end -end - -describe Chef::OpenIDRegistration, "from_json" do - it "should serialize itself as json" do - oreg = Chef::OpenIDRegistration.new() - oreg.name = "foobar" - oreg.set_password("monkey") - oreg_json = oreg.to_json - nreg = JSON.parse(oreg_json) - nreg.should be_a_kind_of(Chef::OpenIDRegistration) - %w{name salt password validated}.each do |verify| - nreg.send(verify.to_sym).should eql(oreg.send(verify.to_sym)) - end - end -end - -describe Chef::OpenIDRegistration, "list" do - before(:each) do - @mock_couch = mock("Chef::CouchDB") - @mock_couch.stub!(:list).and_return({ - "rows" => [ - { - "value" => "a", - "key" => "avenue" - } - ] - }) - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - end - - it "should retrieve a list of nodes from CouchDB" do - Chef::OpenIDRegistration.list.should eql(["avenue"]) - end - - it "should return just the ids if inflate is false" do - Chef::OpenIDRegistration.list(false).should eql(["avenue"]) - end - - it "should return the full objects if inflate is true" do - Chef::OpenIDRegistration.list(true).should eql(["a"]) - end -end - -describe Chef::OpenIDRegistration, "load" do - it "should load a registration from couchdb by name" do - @mock_couch = mock("Chef::CouchDB") - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - @mock_couch.should_receive(:load).with("openid_registration", "coffee").and_return(true) - Chef::OpenIDRegistration.load("coffee") - end -end - -describe Chef::OpenIDRegistration, "destroy" do - it "should delete this registration from couchdb" do - @mock_couch = mock("Chef::CouchDB") - @mock_couch.should_receive(:delete).with("openid_registration", "bob", 1).and_return(true) - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - reg = Chef::OpenIDRegistration.new - reg.name = "bob" - reg.couchdb_rev = 1 - reg.destroy - end -end - -describe Chef::OpenIDRegistration, "save" do - before(:each) do - @mock_couch = mock("Chef::CouchDB") - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - @reg = Chef::OpenIDRegistration.new - @reg.name = "bob" - @reg.couchdb_rev = 1 - end - - it "should save the registration to couchdb" do - @mock_couch.should_receive(:store).with("openid_registration", "bob", @reg).and_return({ "rev" => 33 }) - @reg.save - end - - it "should store the new couchdb_rev" do - @mock_couch.stub!(:store).with("openid_registration", "bob", @reg).and_return({ "rev" => 33 }) - @reg.save - @reg.couchdb_rev.should eql(33) - end -end - -describe Chef::OpenIDRegistration, "create_design_document" do - it "should create our design document" do - mock_couch = mock("Chef::CouchDB") - mock_couch.should_receive(:create_design_document).with("registrations", Chef::OpenIDRegistration::DESIGN_DOCUMENT) - Chef::CouchDB.stub!(:new).and_return(mock_couch) - Chef::OpenIDRegistration.create_design_document - end -end - -describe Chef::OpenIDRegistration, "has_key?" do - it "should check with CouchDB for a registration with this key" do - @mock_couch = mock("Chef::CouchDB") - @mock_couch.should_receive(:has_key?).with("openid_registration", "bob").and_return(true) - Chef::CouchDB.stub!(:new).and_return(@mock_couch) - Chef::OpenIDRegistration.has_key?("bob") - end -end - diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb deleted file mode 100644 index 4eeeebed89..0000000000 --- a/spec/unit/platform_spec.rb +++ /dev/null @@ -1,209 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 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/directory_spec.rb b/spec/unit/provider/directory_spec.rb deleted file mode 100644 index 4978b27288..0000000000 --- a/spec/unit/provider/directory_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 'ostruct' - -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Provider::Directory do - before(:each) do - @new_resource = mock("New Resource", :null_object => true) - @new_resource.stub!(:name).and_return("directory") - @new_resource.stub!(:path).and_return("/tmp") - @new_resource.stub!(:owner).and_return(500) - @new_resource.stub!(:group).and_return(500) - @new_resource.stub!(:mode).and_return(0644) - @new_resource.stub!(:updated).and_return(false) - @node = Chef::Node.new - @node.name "latte" - @directory = Chef::Provider::Directory.new(@node, @new_resource) - end - - it "should load the current resource based on the new resource" do - File.should_receive(:exist?).once.and_return(true) - File.should_receive(:directory?).once.and_return(true) - cstats = mock("stats", :null_object => true) - cstats.stub!(:uid).and_return(500) - cstats.stub!(:gid).and_return(500) - cstats.stub!(:mode).and_return(0755) - File.should_receive(:stat).once.and_return(cstats) - @directory.load_current_resource - @directory.current_resource.path.should eql(@new_resource.path) - @directory.current_resource.owner.should eql(500) - @directory.current_resource.group.should eql(500) - @directory.current_resource.mode.should eql("755") - end - - it "should create a new directory on create, setting updated to true" do - load_mock_provider - File.should_receive(:exists?).once.and_return(false) - Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true) - @directory.new_resource.should_receive(:updated=).with(true) - @directory.should_receive(:set_owner).once.and_return(true) - @directory.should_receive(:set_group).once.and_return(true) - @directory.should_receive(:set_mode).once.and_return(true) - @directory.action_create - end - - it "should not create the directory if it already exists" do - load_mock_provider - File.should_receive(:exists?).once.and_return(true) - Dir.should_not_receive(:mkdir).with(@new_resource.path) - @directory.stub!(:set_owner).and_return(true) - @directory.stub!(:set_group).and_return(true) - @directory.stub!(:set_mode).and_return(true) - @directory.action_create - end - - it "should delete the directory if it exists, and is writable with action_delete" do - load_mock_provider - File.should_receive(:exists?).once.and_return(true) - File.should_receive(:writable?).once.and_return(true) - Dir.should_receive(:delete).with(@new_resource.path).once.and_return(true) - @directory.action_delete - end - - it "should raise an exception if it cannot delete the file due to bad permissions" do - load_mock_provider - File.stub!(:exists?).and_return(true) - File.stub!(:writable?).and_return(false) - lambda { @directory.action_delete }.should raise_error(RuntimeError) - end - - def load_mock_provider - File.stub!(:exist?).and_return(true) - File.stub!(:directory?).and_return(true) - cstats = mock("stats", :null_object => true) - cstats.stub!(:uid).and_return(500) - cstats.stub!(:gid).and_return(500) - cstats.stub!(:mode).and_return(0755) - File.stub!(:stat).once.and_return(cstats) - @directory.load_current_resource - end -end
\ No newline at end of file diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb deleted file mode 100644 index 9ea628a357..0000000000 --- a/spec/unit/provider/file_spec.rb +++ /dev/null @@ -1,224 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 'ostruct' - -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Provider::File do - before(:each) do - @resource = Chef::Resource::File.new("seattle") - @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider::File.new(@node, @resource) - end - - it "should return a Chef::Provider::File" do - @provider.should be_a_kind_of(Chef::Provider::File) - end - - it "should store the resource passed to new as new_resource" do - @provider.new_resource.should eql(@resource) - end - - it "should store the node passed to new as node" do - @provider.node.should eql(@node) - end - - it "should load a current resource based on the one specified at construction" do - @provider.load_current_resource - @provider.current_resource.should be_a_kind_of(Chef::Resource::File) - @provider.current_resource.name.should eql(@resource.name) - @provider.current_resource.path.should eql(@resource.path) - @provider.current_resource.owner.should_not eql(nil) - @provider.current_resource.group.should_not eql(nil) - @provider.current_resource.mode.should_not eql(nil) - end - - it "should load a mostly blank current resource if the file specified in new_resource doesn't exist/isn't readable" do - resource = Chef::Resource::File.new("seattle") - resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "woot.txt")) - node = Chef::Node.new - node.name "latte" - provider = Chef::Provider::File.new(node, resource) - provider.load_current_resource - provider.current_resource.should be_a_kind_of(Chef::Resource::File) - provider.current_resource.name.should eql(resource.name) - provider.current_resource.path.should eql(resource.path) - provider.current_resource.owner.should eql(nil) - provider.current_resource.group.should eql(nil) - provider.current_resource.mode.should eql(nil) - end - - it "should load the correct value for owner of the current resource" do - stats = File.stat(@resource.path) - @provider.load_current_resource - @provider.current_resource.owner.should eql(stats.uid) - end - - it "should load an md5 sum for an existing file" do - @provider.load_current_resource - @provider.current_resource.checksum("8d6152c7d62ea9188eda596c4d31e732") - end - - it "should compare the current owner with the requested owner" do - @provider.load_current_resource - @provider.new_resource.stub!(:owner).and_return("adam") - Etc.stub!(:getpwnam).and_return( - OpenStruct.new( - :name => "adam", - :passwd => "foo", - :uid => 501, - :gid => 501, - :gecos => "Adam Jacob", - :dir => "/Users/adam", - :shell => "/bin/zsh", - :change => "0", - :uclass => "", - :expire => 0 - ) - ) - @provider.current_resource.owner(501) - @provider.compare_owner.should eql(true) - - @provider.current_resource.owner(777) - @provider.compare_owner.should eql(false) - - @provider.new_resource.stub!(:owner).and_return(501) - @provider.current_resource.owner(501) - @provider.compare_owner.should eql(true) - - @provider.new_resource.stub!(:owner).and_return("501") - @provider.current_resource.owner(501) - @provider.compare_owner.should eql(true) - end - - it "should set the ownership on the file to the requested owner" do - @provider.load_current_resource - @provider.new_resource.stub!(:owner).and_return(9982398) - File.stub!(:chown).and_return(1) - File.should_receive(:chown).with(9982398, nil, @provider.current_resource.path) - lambda { @provider.set_owner }.should_not raise_error - end - - it "should raise an exception if you are not root and try to change ownership" do - @provider.load_current_resource - @provider.new_resource.stub!(:owner).and_return(0) - if Process.uid != 0 - lambda { @provider.set_owner }.should raise_error - end - end - - it "should compare the current group with the requested group" do - @provider.load_current_resource - @provider.new_resource.stub!(:group).and_return("adam") - Etc.stub!(:getgrnam).and_return( - OpenStruct.new( - :name => "adam", - :gid => 501 - ) - ) - @provider.current_resource.group(501) - @provider.compare_group.should eql(true) - - @provider.current_resource.group(777) - @provider.compare_group.should eql(false) - - @provider.new_resource.stub!(:group).and_return(501) - @provider.current_resource.group(501) - @provider.compare_group.should eql(true) - - @provider.new_resource.stub!(:group).and_return("501") - @provider.current_resource.group(501) - @provider.compare_group.should eql(true) - end - - it "should set the group on the file to the requested group" do - @provider.load_current_resource - @provider.new_resource.stub!(:group).and_return(9982398) - File.stub!(:chown).and_return(1) - File.should_receive(:chown).with(nil, 9982398, @provider.current_resource.path) - lambda { @provider.set_group }.should_not raise_error - end - - it "should raise an exception if you are not root and try to change the group" do - @provider.load_current_resource - @provider.new_resource.stub!(:group).and_return(0) - if Process.uid != 0 - lambda { @provider.set_group }.should raise_error - end - end - - it "should create the file if it is missing, then set the attributes on action_create" 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 - - it "should delete the file if it exists and is writable on action_delete" do - @provider.load_current_resource - @provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo") - @provider.stub!(:backup).and_return(true) - File.should_receive("exists?").with(@provider.new_resource.path).and_return(true) - File.should_receive("writable?").with(@provider.new_resource.path).and_return(true) - File.should_receive(:delete).with(@provider.new_resource.path).and_return(true) - @provider.action_delete - end - - it "should raise an error if it cannot delete the file" do - @provider.load_current_resource - @provider.stub!(:backup).and_return(true) - @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 - - it "should backup a file no more than :backup times" do - @provider.load_current_resource - @provider.new_resource.stub!(:path).and_return("/tmp/s-20080705111233") - @provider.new_resource.stub!(:backup).and_return(2) - Dir.stub!(:[]).and_return([ "/tmp/s-20080705111233", "/tmp/s-20080705111232", "/tmp/s-20080705111223"]) - FileUtils.should_receive(:rm).with("/tmp/s-20080705111232").once.and_return(true) - FileUtils.should_receive(:rm).with("/tmp/s-20080705111223").once.and_return(true) - FileUtils.stub!(:cp).and_return(true) - File.stub!(:exist?).and_return(true) - @provider.backup - end - -end
\ No newline at end of file diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb deleted file mode 100644 index 462ab9409b..0000000000 --- a/spec/unit/provider/link_spec.rb +++ /dev/null @@ -1,147 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 'ostruct' - -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Provider::Link do - before(:each) do - @new_resource = mock("New Resource", :null_object => true) - @new_resource.stub!(:name).and_return("symlink") - @new_resource.stub!(:source_file).and_return("/tmp/fofile") - @new_resource.stub!(:target_file).and_return("/tmp/fofile-link") - @new_resource.stub!(:link_type).and_return(:symbolic) - @new_resource.stub!(:updated).and_return(false) - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider::Link.new(@node, @new_resource) - end - - it "should load the current resource based on the new resource" do - File.should_receive(:exists?).once.and_return(true) - File.should_receive(:symlink?).once.and_return(true) - File.should_receive(:readlink).once.and_return("/tmp/fofile") - @provider.load_current_resource - @provider.current_resource.name.should eql("symlink") - @provider.current_resource.source_file.should eql("/tmp/fofile") - @provider.current_resource.target_file.should eql("/tmp/fofile-link") - @provider.current_resource.link_type.should eql(:symbolic) - end - - it "should set the current resource's source_file to '' if the target_file doesn't exist" do - File.should_receive(:exists?).once.and_return(true) - File.should_receive(:symlink?).once.and_return(false) - @provider.load_current_resource - @provider.current_resource.source_file.should eql("") - end - - it "should load the current resource if it is a hard link" do - @new_resource.stub!(:link_type).and_return(:hard) - File.should_receive(:exists?).twice.and_return(true) - cstat = mock("stats", :null_object => true) - cstat.stub!(:ino).and_return(1) - File.should_receive(:stat).with("/tmp/fofile-link").and_return(cstat) - File.should_receive(:stat).with("/tmp/fofile").and_return(cstat) - @provider.load_current_resource - @provider.current_resource.name.should eql("symlink") - @provider.current_resource.source_file.should eql("/tmp/fofile") - @provider.current_resource.target_file.should eql("/tmp/fofile-link") - @provider.current_resource.link_type.should eql(:hard) - end - - it "should set the current resource's source_file to '' if the target_file doesn't exist" do - @new_resource.stub!(:link_type).and_return(:hard) - File.should_receive(:exists?).once.and_return(false) - @provider.load_current_resource - @provider.current_resource.source_file.should eql("") - end - - it "should set the current resource's source_file to '' if the two files arent hardlinked" do - @new_resource.stub!(:link_type).and_return(:hard) - File.stub!(:exists?).and_return(true) - cstat = mock("stats", :null_object => true) - cstat.stub!(:ino).and_return(0) - bstat = mock("stats", :null_object => true) - bstat.stub!(:ino).and_return(1) - File.should_receive(:stat).with("/tmp/fofile-link").and_return(cstat) - File.should_receive(:stat).with("/tmp/fofile").and_return(bstat) - @provider.load_current_resource - @provider.current_resource.source_file.should eql("") - end - - it "should create a new symlink on create, setting updated to true" do - load_mock_symlink_provider - @provider.current_resource.source_file("nil") - File.should_receive(:symlink).with(@new_resource.source_file, @new_resource.target_file).once.and_return(true) - @provider.new_resource.should_receive(:updated=).with(true) - @provider.action_create - end - - it "should not create a new symlink on create if it already exists" do - load_mock_symlink_provider - File.should_not_receive(:symlink).with(@new_resource.source_file, @new_resource.target_file) - @provider.action_create - end - - it "should create a new hard link on create, setting updated to true" do - load_mock_hardlink_provider - @provider.current_resource.source_file("nil") - File.should_receive(:link).with(@new_resource.source_file, @new_resource.target_file).once.and_return(true) - @provider.new_resource.should_receive(:updated=).with(true) - @provider.action_create - end - - it "should not create a new hard link on create if it already exists" do - load_mock_symlink_provider - File.should_not_receive(:link).with(@new_resource.source_file, @new_resource.target_file) - @provider.action_create - end - - it "should delete the link if it exists, and is writable with action_delete" do - load_mock_symlink_provider - File.should_receive(:exists?).once.and_return(true) - File.should_receive(:writable?).once.and_return(true) - File.should_receive(:delete).with(@new_resource.target_file).once.and_return(true) - @provider.action_delete - end - - it "should raise an exception if it cannot delete the link due to bad permissions" do - load_mock_symlink_provider - File.stub!(:exists?).and_return(true) - File.stub!(:writable?).and_return(false) - lambda { @provider.action_delete }.should raise_error(RuntimeError) - end - - def load_mock_symlink_provider - File.stub!(:exists?).and_return(true) - File.stub!(:symlink?).and_return(true) - File.stub!(:readlink).and_return("/tmp/fofile") - @provider.load_current_resource - end - - def load_mock_hardlink_provider - @new_resource.stub!(:link_type).and_return(:hard) - File.stub!(:exists?).twice.and_return(true) - cstat = mock("stats", :null_object => true) - cstat.stub!(:ino).and_return(1) - File.stub!(:stat).with("/tmp/fofile-link").and_return(cstat) - File.stub!(:stat).with("/tmp/fofile").and_return(cstat) - @provider.load_current_resource - end -end
\ No newline at end of file diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb deleted file mode 100644 index 51c48d0f9a..0000000000 --- a/spec/unit/provider/remote_file_spec.rb +++ /dev/null @@ -1,152 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Provider::RemoteFile, "action_create" do - before(:each) do - @resource = Chef::Resource::RemoteFile.new("seattle") - @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) - @resource.source("http://foo") - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider::RemoteFile.new(@node, @resource) - @provider.current_resource = @resource.clone - end - - it "should call do_remote_file" do - @provider.should_receive(:do_remote_file).with(@resource.source, @resource.path) - @provider.action_create - end - -end - -describe Chef::Provider::RemoteFile, "do_remote_file" do - before(:each) do - @rest = mock(Chef::REST, { }) - @tempfile = mock(Tempfile, { :path => "/tmp/foo", }) - @rest.stub!(:get_rest).and_return(@tempfile) - @resource = Chef::Resource::RemoteFile.new("seattle") - @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) - @resource.source("foo") - @resource.cookbook_name = "monkey" - @node = Chef::Node.new - @node.name "latte" - @node.fqdn "latte.local" - @provider = Chef::Provider::RemoteFile.new(@node, @resource) - @provider.stub!(:checksum).and_return("dad86c61eea237932f201009e5431609") - @provider.current_resource = @resource.clone - @provider.current_resource.checksum("dad86c61eea237932f201009e5431609") - File.stub!(:exists?).and_return(true) - FileUtils.stub!(:cp).and_return(true) - Chef::Platform.stub!(:find_platform_and_version).and_return([ :mac_os_x, "10.5.1" ]) - end - - def do_remote_file - Chef::REST.stub!(:new).and_return(@rest) - @provider.do_remote_file(@resource.source, @resource.path) - end - - it "should set the checksum if the file exists" do - @provider.should_receive(:checksum).with(@resource.path) - do_remote_file - end - - it "should not set the checksum if the file doesn't exist" do - File.stub!(:exists?).with(@resource.path).and_return(false) - @provider.should_not_receive(:checksum).with(@resource.path) - do_remote_file - end - - it "should call generate_url with the current checksum as an extra attribute" do - @provider.should_receive(:generate_url).with(@resource.source, "files", { :checksum => "dad86c61eea237932f201009e5431609"}) - do_remote_file - end - - it "should call get_rest with a correctly composed url" do - url = "cookbooks/#{@resource.cookbook_name}/files?id=#{@resource.source}" - url += "&platform=mac_os_x" - url += "&version=10.5.1" - url += "&fqdn=latte.local" - url += "&checksum=dad86c61eea237932f201009e5431609" - @rest.should_receive(:get_rest).with(url, true).and_return(@tempfile) - do_remote_file - end - - it "should not transfer the file if it has not been changed" do - r = Net::HTTPNotModified.new("one", "two", "three") - e = Net::HTTPRetriableError.new("304", r) - @rest.stub!(:get_rest).and_raise(e) - do_remote_file.should eql(false) - end - - it "should raise an exception if it's any other kind of retriable response than 304" do - r = Net::HTTPMovedPermanently.new("one", "two", "three") - e = Net::HTTPRetriableError.new("301", r) - @rest.stub!(:get_rest).and_raise(e) - lambda { do_remote_file }.should raise_error(Net::HTTPRetriableError) - end - - it "should raise an exception if anything else happens" do - r = Net::HTTPBadRequest.new("one", "two", "three") - e = Net::HTTPServerException.new("fake exception", r) - @rest.stub!(:get_rest).and_raise(e) - lambda { do_remote_file }.should raise_error(Net::HTTPServerException) - end - - it "should checksum the raw file" do - @provider.should_receive(:checksum).with(@tempfile.path).and_return("dad86c61eea237932f201009e5431608") - do_remote_file - end - - it "should backup the original file" do - @provider.should_receive(:backup).with(@resource.path).and_return(true) - do_remote_file - end - - it "should set the new resource to updated" do - @resource.should_receive(:updated=).with(true) - do_remote_file - end - - it "should copy the raw file to the new resource" do - FileUtils.should_receive(:cp).with(@tempfile.path, @resource.path).and_return(true) - do_remote_file - end - - it "should set the owner if provided" do - @resource.owner("adam") - @provider.should_receive(:set_owner).and_return(true) - do_remote_file - end - - it "should set the group if provided" do - @resource.group("adam") - @provider.should_receive(:set_group).and_return(true) - do_remote_file - end - - it "should set the mode if provided" do - @resource.mode(0676) - @provider.should_receive(:set_mode).and_return(true) - do_remote_file - end - -# TODO: Finish these tests - -end diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb deleted file mode 100644 index abc98e2ea3..0000000000 --- a/spec/unit/provider/template_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Provider::Template, "action_create" do - before(:each) do - @rest = mock(Chef::REST, { :get_rest => "/tmp/foobar" }) - @tempfile = mock(Tempfile, { :path => "/tmp/foo", }) - @rest.stub!(:get_rest).and_return(@tempfile) - @resource = Chef::Resource::Template.new("seattle") - @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) - @resource.source("http://foo") - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider::Template.new(@node, @resource) - @provider.stub!(:checksum).and_return("dad86c61eea237932f201009e5431609") - @provider.current_resource = @resource.clone - @provider.current_resource.checksum("dad86c61eea237932f201009e5431609") - FileUtils.stub!(:cp).and_return(true) - end - - def do_action_create - Chef::REST.stub!(:new).and_return(@rest) - @provider.action_create - end - - it "should get the template based on the resources source value" do - @rest.should_receive(:get_rest).with(@resource.source, true).and_return(@tempfile) - do_action_create - end - - it "should set the checksum of the new resource to the value of the returned template" do - @resource.should_receive(:checksum).with("dad86c61eea237932f201009e5431609").once - @resource.should_receive(:checksum).twice - do_action_create - end - - it "should not copy the tempfile to the real file if the checksums match" do - FileUtils.should_not_receive(:cp) - do_action_create - end - - it "should copy the tempfile to the real file if the checksums do not match" do - @provider.stub!(:checksum).and_return("dad86c61eea237932f201009e5431607") - FileUtils.should_receive(:cp).once - @provider.stub!(:backup).and_return(true) - do_action_create - end - - it "should set the owner if provided" do - @resource.owner("adam") - @provider.should_receive(:set_owner).and_return(true) - do_action_create - end - - it "should set the group if provided" do - @resource.group("adam") - @provider.should_receive(:set_group).and_return(true) - do_action_create - end - - it "should set the mode if provided" do - @resource.mode(0676) - @provider.should_receive(:set_mode).and_return(true) - do_action_create - end -end - -describe Chef::Provider::Template, "generate_url" do - - before(:each) do - @resource = Chef::Resource::Template.new("seattle") - @resource.cookbook_name = "daft" - @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider::Template.new(@node, @resource) - end - - it "should return a raw url if it starts with http" do - @provider.generate_url('http://foobar', "templates").should eql("http://foobar") - end - - it "should return a composed url if it does not start with http" do - Chef::Platform.stub!(:find_platform_and_version).and_return(["monkey", "1.0"]) - @node.fqdn("monkeynode") - @provider.generate_url('default/something', "templates").should eql("cookbooks/daft/templates?id=default/something&platform=monkey&version=1.0&fqdn=monkeynode") - end -end
\ No newline at end of file diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb deleted file mode 100644 index 0512012598..0000000000 --- a/spec/unit/provider_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Provider do - before(:each) do - @resource = Chef::Resource.new("funk") - @node = Chef::Node.new - @node.name "latte" - @provider = Chef::Provider.new(@node, @resource) - end - - it "should return a Chef::Provider" do - @provider.should be_a_kind_of(Chef::Provider) - end - - it "should store the resource passed to new as new_resource" do - @provider.new_resource.should eql(@resource) - end - - it "should store the node passed to new as node" do - @provider.node.should eql(@node) - end - - 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/queue_spec.rb b/spec/unit/queue_spec.rb deleted file mode 100644 index e902f44631..0000000000 --- a/spec/unit/queue_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Queue do - - it "should connect to a stomp server on localhost and 61613" do - Stomp::Connection.should_receive(:open).with("", "", "localhost", 61613, false).once - Chef::Queue.connect - end - - it "should allow config options to override defaults on connect" do - Chef::Config[:queue_user] = "monkey" - Chef::Config[:queue_password] = "password" - Chef::Config[:queue_host] = "10.10.10.10" - Chef::Config[:queue_port] = 61614 - Stomp::Connection.should_receive(:open).with("monkey", "password", "10.10.10.10", 61614, false).once - Chef::Queue.connect - end - - it "should make a url based on type and name" do - Chef::Queue.make_url("topic", "goal").should eql("/topic/chef/goal") - Chef::Queue.make_url("queue", "pool").should eql("/queue/chef/pool") - end - - it "should allow you to subscribe to a queue" do - queue = mock("Queue", :null_object => true) - queue.should_receive(:subscribe).with(Chef::Queue.make_url(:topic, :node)).once - Stomp::Connection.stub!(:open).and_return(queue) - Chef::Queue.connect - Chef::Queue.subscribe(:topic, :node) - end - - it "should allow you to send a message" do - message = mock("Message", :null_object => true) - message.should_receive(:to_json).once.and_return("some json") - connection = mock("Connection", :null_object => true) - connection.should_receive(:send).with(Chef::Queue.make_url(:queue, :node), "some json").once.and_return(true) - Stomp::Connection.stub!(:open).and_return(connection) - Chef::Queue.connect - Chef::Queue.send_msg(:queue, :node, message) - end - - it "should receive a message with receive_msg" do - raw_msg = mock("Stomp Message", :null_object => true) - raw_msg.should_receive(:body).twice.and_return("the body") - connection = mock("Connection", :null_object => true) - connection.should_receive(:receive).once.and_return(raw_msg) - JSON.should_receive(:parse).with("the body").and_return("the body") - Stomp::Connection.stub!(:open).and_return(connection) - Chef::Queue.connect - Chef::Queue.receive_msg.should eql([ "the body", raw_msg ]) - end - - it "should poll for a message with poll_msg, returning a message if there is one" do - raw_msg = mock("Stomp Message", :null_object => true) - raw_msg.should_receive(:body).once.and_return("the body") - connection = mock("Connection", :null_object => true) - connection.should_receive(:poll).once.and_return(raw_msg) - JSON.should_receive(:parse).with("the body").and_return("the body") - Stomp::Connection.stub!(:open).and_return(connection) - Chef::Queue.connect - Chef::Queue.poll_msg.should eql("the body") - end - - it "should poll for a message with poll_msg, returning nil if there is not a message" do - connection = mock("Connection", :null_object => true) - connection.should_receive(:poll).once.and_return(nil) - JSON.should_not_receive(:parse).with(nil) - Stomp::Connection.stub!(:open).and_return(connection) - Chef::Queue.connect - Chef::Queue.poll_msg.should eql(nil) - end - - it "should raise an exception if you disconnect without a connection" do - Stomp::Connection.stub!(:open).and_return(nil) - Chef::Queue.connect - lambda { Chef::Queue.disconnect }.should raise_error(ArgumentError) - end - - it "should disconnect an active connection" do - connection = mock("Connection", :null_object => true) - connection.should_receive(:disconnect).once.and_return(true) - Stomp::Connection.stub!(:open).and_return(connection) - Chef::Queue.connect - Chef::Queue.disconnect - end - -end
\ No newline at end of file diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb deleted file mode 100644 index 77d5354993..0000000000 --- a/spec/unit/recipe_spec.rb +++ /dev/null @@ -1,143 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Recipe do - before(:each) do - @recipe = Chef::Recipe.new("hjk", "test", Chef::Node.new) - end - - it "should load a two word (zen_master) resource" do - lambda do - @recipe.zen_master "monkey" do - 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 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.collection.lookup("zen_master[monkey]").name.should eql("monkey") - end - - 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 - end - end - @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 - 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 -zen_master "gnome" do - peace = true -end -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 resource 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.action.should eql(:create) - 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 - - it "should evaluate another recipe with recipe_require" do - Chef::Config.cookbook_path File.join(File.dirname(__FILE__), "..", "data", "cookbooks") - @recipe.cookbook_loader.load_cookbooks - @recipe.require_recipe "openldap::gigantor" - res = @recipe.resources(:cat => "blanket") - res.name.should eql("blanket") - res.pretty_kitty.should eql(false) - end - - it "should load the default recipe for a cookbook if require_recipe is called without a ::" do - Chef::Config.cookbook_path File.join(File.dirname(__FILE__), "..", "data", "cookbooks") - @recipe.cookbook_loader.load_cookbooks - @recipe.require_recipe "openldap" - res = @recipe.resources(:cat => "blanket") - res.name.should eql("blanket") - res.pretty_kitty.should eql(true) - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/bash_spec.rb b/spec/unit/resource/bash_spec.rb deleted file mode 100644 index f86e63d32e..0000000000 --- a/spec/unit/resource/bash_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Bash do - - before(:each) do - @resource = Chef::Resource::Bash.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Bash" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Bash) - end - - it "should have a resource name of :bash" do - @resource.resource_name.should eql(:bash) - end - - it "should have an interpreter of bash" do - @resource.interpreter.should eql("bash") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/csh_spec.rb b/spec/unit/resource/csh_spec.rb deleted file mode 100644 index 67ba4499fa..0000000000 --- a/spec/unit/resource/csh_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Csh do - - before(:each) do - @resource = Chef::Resource::Csh.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Csh" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Csh) - end - - it "should have a resource name of :csh" do - @resource.resource_name.should eql(:csh) - end - - it "should have an interpreter of csh" do - @resource.interpreter.should eql("csh") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb deleted file mode 100644 index 98cc28fbc6..0000000000 --- a/spec/unit/resource/directory_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 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::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/execute_spec.rb b/spec/unit/resource/execute_spec.rb deleted file mode 100644 index 94cb3d3d92..0000000000 --- a/spec/unit/resource/execute_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Execute do - - before(:each) do - @resource = Chef::Resource::Execute.new("some command") - end - - it "should create a new Chef::Resource::Execute" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Execute) - end - - it "should set the command to the first argument to new" do - @resource.command.should eql("some command") - end - - it "should accept a string for the command to run" do - @resource.command "something" - @resource.command.should eql("something") - end - - it "should accept a string for the cwd" do - @resource.cwd "something" - @resource.cwd.should eql("something") - end - - it "should accept a hash for the environment" do - test_hash = { :one => :two } - @resource.environment(test_hash) - @resource.environment.should eql(test_hash) - end - - it "should accept a string for the group" do - @resource.group "something" - @resource.group.should eql("something") - end - - it "should accept an integer for the group" do - @resource.group 1 - @resource.group.should eql(1) - end - - it "should accept a string for onlyif" do - @resource.onlyif "woot" - @resource.onlyif.should eql("woot") - end - - it "should accept an array for the execution path" do - @resource.path ["woot"] - @resource.path.should eql(["woot"]) - end - - it "should accept an integer for the return code" do - @resource.returns 1 - @resource.returns.should eql(1) - end - - it "should accept an integer for the timeout" do - @resource.timeout 1 - @resource.timeout.should eql(1) - end - - it "should accept a string for unless" do - @resource.unless "woot" - @resource.unless.should eql("woot") - end - - it "should accept a string for the user" do - @resource.user "something" - @resource.user.should eql("something") - end - - it "should accept an integer for the user" do - @resource.user 1 - @resource.user.should eql(1) - end - - it "should accept a string for creates" do - @resource.creates "something" - @resource.creates.should eql("something") - end - -end diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb deleted file mode 100644 index b67598d738..0000000000 --- a/spec/unit/resource/file_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::File do - - before(:each) do - @resource = Chef::Resource::File.new("fakey_fakerton") - end - - 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 - @resource.name.should eql("fakey_fakerton") - end - - it "should have a default action of 'create'" do - @resource.action.should eql("create") - end - - it "should be set to back up 5 files by default" do - @resource.backup.should eql(5) - end - - it "should only accept false or a number for backup" do - lambda { @resource.backup true }.should raise_error(ArgumentError) - lambda { @resource.backup false }.should_not raise_error(ArgumentError) - lambda { @resource.backup 10 }.should_not raise_error(ArgumentError) - lambda { @resource.backup "blues" }.should raise_error(ArgumentError) - end - - it "should accept an md5sum for checksum" do - lambda { @resource.checksum "bfda9e7a13afb123433667c2c7801d11" }.should_not raise_error(ArgumentError) - lambda { @resource.checksum "monkey!" }.should raise_error(ArgumentError) - end - - it "should accept create, delete or touch for action" do - lambda { @resource.action "create" }.should_not raise_error(ArgumentError) - lambda { @resource.action "delete" }.should_not raise_error(ArgumentError) - lambda { @resource.action "touch" }.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) - @resource.mode.should eql(0444) - 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) - @resource.path.should eql("/tmp") - lambda { @resource.path Hash.new }.should raise_error(ArgumentError) - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb deleted file mode 100644 index fa0810cced..0000000000 --- a/spec/unit/resource/link_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Link do - - before(:each) do - @resource = Chef::Resource::Link.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Link" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Link) - 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 use the object name as the source_file by default" do - @resource.source_file.should eql("fakey_fakerton") - end - - it "should accept a string as the source_file" do - lambda { @resource.source_file "/tmp" }.should_not raise_error(ArgumentError) - lambda { @resource.source_file Hash.new }.should raise_error(ArgumentError) - end - - it "should allow you to set a target_file" do - @resource.target_file "/tmp/foo" - @resource.target_file.should eql("/tmp/foo") - end - - it "should allow you to specify the link type" do - @resource.link_type "symbolic" - @resource.link_type.should eql(:symbolic) - end - - it "should default to a symbolic link" do - @resource.link_type.should eql(:symbolic) - end - - it "should accept a hard link_type" do - @resource.link_type :hard - @resource.link_type.should eql(:hard) - end - - it "should reject any other link_type but :hard and :symbolic" do - lambda { @resource.link_type "x-men" }.should raise_error(ArgumentError) - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb deleted file mode 100644 index 8756e4f603..0000000000 --- a/spec/unit/resource/package_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Package do - - before(:each) do - @resource = Chef::Resource::Package.new("emacs") - end - - it "should create a new Chef::Resource::Package" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Package) - end - - it "should set the package_name to the first argument to new" do - @resource.package_name.should eql("emacs") - end - - it "should accept a string for the package name" do - @resource.package_name "something" - @resource.package_name.should eql("something") - end - - it "should accept a string for the version" do - @resource.version "something" - @resource.version.should eql("something") - end - - it "should accept a string for the response file" do - @resource.response_file "something" - @resource.response_file.should eql("something") - end - - it "should accept a string for the source" do - @resource.source "something" - @resource.source.should eql("something") - end - -end diff --git a/spec/unit/resource/perl_spec.rb b/spec/unit/resource/perl_spec.rb deleted file mode 100644 index 528bcef08c..0000000000 --- a/spec/unit/resource/perl_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Perl do - - before(:each) do - @resource = Chef::Resource::Perl.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Perl" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Perl) - end - - it "should have a resource name of :perl" do - @resource.resource_name.should eql(:perl) - end - - it "should have an interpreter of perl" do - @resource.interpreter.should eql("perl") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/python_spec.rb b/spec/unit/resource/python_spec.rb deleted file mode 100644 index 11c5b84d04..0000000000 --- a/spec/unit/resource/python_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Python do - - before(:each) do - @resource = Chef::Resource::Python.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Python" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Python) - end - - it "should have a resource name of :python" do - @resource.resource_name.should eql(:python) - end - - it "should have an interpreter of python" do - @resource.interpreter.should eql("python") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb deleted file mode 100644 index 2d9ce122af..0000000000 --- a/spec/unit/resource/remote_directory_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::RemoteDirectory do - - before(:each) do - @resource = Chef::Resource::RemoteDirectory.new("/etc/dunk") - end - - it "should create a new Chef::Resource::RemoteDirectory" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::RemoteDirectory) - end - - it "should set the path to the first argument to new" do - @resource.path.should eql("/etc/dunk") - end - - it "should accept a string for the remote directory source" do - @resource.source "foo" - @resource.source.should eql("foo") - end - - it "should accept a number for the remote files backup" do - @resource.files_backup 1 - @resource.files_backup.should eql(1) - end - - it "should accept false for the remote files backup" do - @resource.files_backup false - @resource.files_backup.should eql(false) - end - - it "should accept 3 or 4 digets for the files_mode" do - @resource.files_mode 100 - @resource.files_mode.should eql(100) - @resource.files_mode 1000 - @resource.files_mode.should eql(1000) - end - - it "should accept a string or number for the files group" do - @resource.files_group "heart" - @resource.files_group.should eql("heart") - @resource.files_group 1000 - @resource.files_group.should eql(1000) - end - - it "should accept a string or number for the files owner" do - @resource.files_owner "heart" - @resource.files_owner.should eql("heart") - @resource.files_owner 1000 - @resource.files_owner.should eql(1000) - end -end diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb deleted file mode 100644 index 4c052e0260..0000000000 --- a/spec/unit/resource/remote_file_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::RemoteFile do - - before(:each) do - @resource = Chef::Resource::RemoteFile.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::RemoteFile" 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::RemoteFile) - end - - it "should accept a string for the remote file source" do - @resource.source "something" - @resource.source.should eql("something") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/ruby_spec.rb b/spec/unit/resource/ruby_spec.rb deleted file mode 100644 index 5351462154..0000000000 --- a/spec/unit/resource/ruby_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Ruby do - - before(:each) do - @resource = Chef::Resource::Ruby.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Ruby" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Ruby) - end - - it "should have a resource name of :ruby" do - @resource.resource_name.should eql(:ruby) - end - - it "should have an interpreter of ruby" do - @resource.interpreter.should eql("ruby") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb deleted file mode 100644 index f003028fd6..0000000000 --- a/spec/unit/resource/script_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Script do - - before(:each) do - @resource = Chef::Resource::Script.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Script" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Script) - end - - it "should have a resource name of :script" do - @resource.resource_name.should eql(:script) - end - - it "should set command to the argument provided to new" do - @resource.command.should eql("fakey_fakerton") - end - - it "should accept a string for the code" do - @resource.code "hey jude" - @resource.code.should eql("hey jude") - end - - it "should accept a string for the interpreter" do - @resource.interpreter "naaaaNaNaNaaNaaNaaNaa" - @resource.interpreter.should eql("naaaaNaNaNaaNaaNaaNaa") - end - -end
\ No newline at end of file diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb deleted file mode 100644 index f5941f89ae..0000000000 --- a/spec/unit/resource/service_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# -# Author:: AJ Christensen (<aj@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Service do - - before(:each) do - @resource = Chef::Resource::Service.new("chef") - end - - it "should create a new Chef::Resource::Service" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Service) - end - - it "should set the service_name to the first argument to new" do - @resource.service_name.should eql("chef") - end - - it "should set the pattern to be the service name by default" do - @resource.pattern.should eql("chef") - end - - it "should accept a string for the service name" do - @resource.service_name "something" - @resource.service_name.should eql("something") - end - - it "should accept a string for the service pattern" do - @resource.pattern ".*" - @resource.pattern.should eql(".*") - end - - it "should not accept a regexp for the service pattern" do - lambda { - @resource.pattern /.*/ - }.should raise_error(ArgumentError) - end - - it "should accept a string for the service start command" do - @resource.start_command "/etc/init.d/chef start" - @resource.start_command.should eql("/etc/init.d/chef start") - end - - it "should not accept a regexp for the service start command" do - lambda { - @resource.start_command /.*/ - }.should raise_error(ArgumentError) - end - - it "should accept a string for the service stop command" do - @resource.stop_command "/etc/init.d/chef stop" - @resource.stop_command.should eql("/etc/init.d/chef stop") - end - - it "should not accept a regexp for the service stop command" do - lambda { - @resource.stop_command /.*/ - }.should raise_error(ArgumentError) - end - - it "should accept a string for the service status command" do - @resource.status_command "/etc/init.d/chef status" - @resource.status_command.should eql("/etc/init.d/chef status") - end - - it "should not accept a regexp for the service status command" do - lambda { - @resource.status_command /.*/ - }.should raise_error(ArgumentError) - end - - it "should accept a string for the service restart command" do - @resource.restart_command "/etc/init.d/chef restart" - @resource.restart_command.should eql("/etc/init.d/chef restart") - end - - it "should not accept a regexp for the service restart command" do - lambda { - @resource.restart_command /.*/ - }.should raise_error(ArgumentError) - end - -end diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb deleted file mode 100644 index 106fe77bda..0000000000 --- a/spec/unit/resource/template_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) - -describe Chef::Resource::Template do - - before(:each) do - @resource = Chef::Resource::Template.new("fakey_fakerton") - end - - it "should create a new Chef::Resource::Template" 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::Template) - end - - it "should accept a string for the template source" do - @resource.source "something" - @resource.source.should eql("something") - end - - it "should accept a hash for the variable list" do - @resource.variables({ :reluctance => :awkward }) - @resource.variables.should == { :reluctance => :awkward } - end - -end
\ No newline at end of file diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb deleted file mode 100644 index 37eeac18db..0000000000 --- a/spec/unit/resource_collection_spec.rb +++ /dev/null @@ -1,201 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(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 through [index]" do - lambda { @rc[0] = @resource }.should_not raise_error - lambda { @rc[0] = "string" }.should raise_error - end - - it "should not accept duplicate resources [index]=" do - @rc[0] = @resource - lambda { @rc[1] = @resource }.should raise_error(ArgumentError) - 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 not accept duplicate resources through pushing" do - lambda { @rc.push(@resource) }.should_not raise_error - lambda { @rc.push(@resource) }.should raise_error(ArgumentError) - 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 not accept duplicate resources through the << operator" do - lambda { @rc << @resource }.should_not raise_error - lambda { @rc << @resource }.should raise_error(ArgumentError) - 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 - - it "should serialize to json" do - json = @rc.to_json - json.should =~ /json_class/ - json.should =~ /instance_vars/ - end - - it "should deserialize itself from json" do - @rc << @resource - json = @rc.to_json - s_rc = JSON.parse(json) - s_rc.should be_a_kind_of(Chef::ResourceCollection) - s_rc[0].name.should eql(@resource.name) - 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 deleted file mode 100644 index 8ba7556b70..0000000000 --- a/spec/unit/resource_definition_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(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 deleted file mode 100644 index 3ca48060fa..0000000000 --- a/spec/unit/resource_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Resource do - before(:each) do - @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 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 - lambda { @resource.name false }.should raise_error(ArgumentError) - end - - it "should always have a string for name" do - lambda { @resource.name Hash.new }.should raise_error(ArgumentError) - end - - it "should accept true or false for noop" do - lambda { @resource.noop true }.should_not raise_error(ArgumentError) - lambda { @resource.noop false }.should_not raise_error(ArgumentError) - lambda { @resource.noop "eat it" }.should raise_error(ArgumentError) - end - - 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 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 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 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.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 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][:delayed][0].name.should eql("funk") - end - - 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][: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 = 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 json" do - json = @resource.to_json - json.should =~ /json_class/ - json.should =~ /instance_vars/ - end - - it "should deserialize itself from json" do - json = @resource.to_json - serialized_node = JSON.parse(json) - serialized_node.should be_a_kind_of(Chef::Resource) - serialized_node.name.should eql(@resource.name) - end - -end
\ No newline at end of file diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb deleted file mode 100644 index 56c2954a1a..0000000000 --- a/spec/unit/rest_spec.rb +++ /dev/null @@ -1,228 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) -require 'uri' -require 'net/https' - -describe Chef::REST, "initialize method" do - it "should create a new Chef::REST" do - Chef::REST.new("url").should be_kind_of(Chef::REST) - end -end - -describe Chef::REST, "get_rest method" do - it "should create a url from the path and base url" do - URI.should_receive(:parse).with("url/monkey") - r = Chef::REST.new("url") - r.stub!(:run_request) - r.get_rest("monkey") - end - - it "should call run_request :GET with the composed url object" do - URI.stub!(:parse).and_return(true) - r = Chef::REST.new("url") - r.should_receive(:run_request).with(:GET, true, false, 10, false).and_return(true) - r.get_rest("monkey") - end -end - -describe Chef::REST, "delete_rest method" do - it "should create a url from the path and base url" do - URI.should_receive(:parse).with("url/monkey") - r = Chef::REST.new("url") - r.stub!(:run_request) - r.delete_rest("monkey") - end - - it "should call run_request :DELETE with the composed url object" do - URI.stub!(:parse).and_return(true) - r = Chef::REST.new("url") - r.should_receive(:run_request).with(:DELETE, true).and_return(true) - r.delete_rest("monkey") - end -end - -describe Chef::REST, "post_rest method" do - it "should create a url from the path and base url" do - URI.should_receive(:parse).with("url/monkey") - r = Chef::REST.new("url") - r.stub!(:run_request) - r.post_rest("monkey", "data") - end - - it "should call run_request :POST with the composed url object and data" do - URI.stub!(:parse).and_return(true) - r = Chef::REST.new("url") - r.should_receive(:run_request).with(:POST, true, "data").and_return(true) - r.post_rest("monkey", "data") - end -end - -describe Chef::REST, "put_rest method" do - it "should create a url from the path and base url" do - URI.should_receive(:parse).with("url/monkey") - r = Chef::REST.new("url") - r.stub!(:run_request) - r.put_rest("monkey", "data") - end - - it "should call run_request :PUT with the composed url object and data" do - URI.stub!(:parse).and_return(true) - r = Chef::REST.new("url") - r.should_receive(:run_request).with(:PUT, true, "data").and_return(true) - r.put_rest("monkey", "data") - end -end - -describe Chef::REST, "run_request method" do - before(:each) do - @r = Chef::REST.new("url") - @url_mock = mock("URI", :null_object => true) - @url_mock.stub!(:host).and_return("one") - @url_mock.stub!(:port).and_return("80") - @url_mock.stub!(:path).and_return("/") - @url_mock.stub!(:query).and_return("foo=bar") - @url_mock.stub!(:scheme).and_return("https") - @url_mock.stub!(:to_s).and_return("https://one:80/?foo=bar") - @http_response_mock = mock("Net::HTTPSuccess", :null_object => true) - @http_response_mock.stub!(:kind_of?).with(Net::HTTPSuccess).and_return(true) - @http_response_mock.stub!(:body).and_return("ninja") - @http_mock = mock("Net::HTTP", :null_object => true) - @http_mock.stub!(:verify_mode=).and_return(true) - @http_mock.stub!(:read_timeout=).and_return(true) - @http_mock.stub!(:use_ssl=).with(true).and_return(true) - @data_mock = mock("Data", :null_object => true) - @data_mock.stub!(:to_json).and_return('{ "one": "two" }') - @request_mock = mock("Request", :null_object => true) - @request_mock.stub!(:body=).and_return(true) - @request_mock.stub!(:method).and_return(true) - @request_mock.stub!(:path).and_return(true) - @http_mock.stub!(:request).and_return(@http_response_mock) - @tf_mock = mock(Tempfile, { :print => true, :close => true }) - Tempfile.stub!(:new).with("chef-rest").and_return(@tf_mock) - end - - def do_run_request(method=:GET, data=false, limit=10, raw=false) - Net::HTTP.stub!(:new).and_return(@http_mock) - @r.run_request(method, @url_mock, data, limit, raw) - end - - it "should raise an exception if the redirect limit is 0" do - lambda { @r.run_request(:GET, "/", false, 0)}.should raise_error(ArgumentError) - end - - it "should use SSL if the url starts with https" do - @url_mock.should_receive(:scheme).and_return("https") - @http_mock.should_receive(:use_ssl=).with(true).and_return(true) - do_run_request - end - - it "should set the OpenSSL Verify Mode to verify_none if requested" do - @http_mock.should_receive(:verify_mode=).and_return(true) - do_run_request - end - - it "should set a read timeout based on the rest_timeout config option" do - Chef::Config[:rest_timeout] = 10 - @http_mock.should_receive(:read_timeout=).with(10).and_return(true) - do_run_request - end - - it "should build a new HTTP GET request" do - Net::HTTP::Get.should_receive(:new).with("/?foo=bar", - { 'Accept' => 'application/json' } - ).and_return(@request_mock) - do_run_request - end - - it "should build a new HTTP POST request" do - Net::HTTP::Post.should_receive(:new).with("/", - { 'Accept' => 'application/json', "Content-Type" => 'application/json' } - ).and_return(@request_mock) - do_run_request(:POST, @data_mock) - end - - it "should build a new HTTP PUT request" do - Net::HTTP::Put.should_receive(:new).with("/", - { 'Accept' => 'application/json', "Content-Type" => 'application/json' } - ).and_return(@request_mock) - do_run_request(:PUT, @data_mock) - end - - it "should build a new HTTP DELETE request" do - Net::HTTP::Delete.should_receive(:new).with("/?foo=bar", - { 'Accept' => 'application/json' } - ).and_return(@request_mock) - do_run_request(:DELETE) - end - - it "should raise an error if the method is not GET/PUT/POST/DELETE" do - lambda { do_run_request(:MONKEY) }.should raise_error(ArgumentError) - end - - it "should run an http request" do - @http_mock.should_receive(:request).and_return(@http_response_mock) - do_run_request - end - - it "should return the body of the response on success" do - do_run_request.should eql("ninja") - end - - it "should inflate the body as to an object if JSON is returned" do - @http_response_mock.stub!(:[]).with('content-type').and_return("application/json") - JSON.should_receive(:parse).with("ninja").and_return(true) - do_run_request - end - - it "should call run_request again on a Redirect response" do - @http_response_mock.stub!(:kind_of?).with(Net::HTTPSuccess).and_return(false) - @http_response_mock.stub!(:kind_of?).with(Net::HTTPFound).and_return(true) - @http_response_mock.stub!(:[]).with('location').and_return(@url_mock.path) - lambda { do_run_request(method=:GET, data=false, limit=1) }.should raise_error(ArgumentError) - end - - it "should raise an exception on an unsuccessful request" do - @http_response_mock.stub!(:kind_of?).with(Net::HTTPSuccess).and_return(false) - @http_response_mock.stub!(:kind_of?).with(Net::HTTPFound).and_return(false) - @http_response_mock.should_receive(:error!) - do_run_request - end - - it "should build a new HTTP GET request without the application/json accept header for raw reqs" do - Net::HTTP::Get.should_receive(:new).with("/?foo=bar", {}).and_return(@request_mock) - do_run_request(:GET, false, 10, true) - end - - it "should create a tempfile for the output of a raw request" do - Tempfile.should_receive(:new).with("chef-rest").and_return(@tf_mock) - do_run_request(:GET, false, 10, true).should eql(@tf_mock) - end - - it "should populate the tempfile with the value of the raw request" do - @tf_mock.should_receive(:print, "ninja").once.and_return(true) - do_run_request(:GET, false, 10, true) - end - - it "should close the tempfile if we're doing a raw request" do - @tf_mock.should_receive(:close).once.and_return(true) - do_run_request(:GET, false, 10, true) - end - -end diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb deleted file mode 100644 index f73d5efb22..0000000000 --- a/spec/unit/runner_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 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 diff --git a/spec/unit/search_index_spec.rb b/spec/unit/search_index_spec.rb deleted file mode 100644 index ff234c6a41..0000000000 --- a/spec/unit/search_index_spec.rb +++ /dev/null @@ -1,136 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::SearchIndex, "initialize method" do - it "should create a new Chef::SearchIndex object" do - mf = mock("Ferret::Index::Index", :null_object => true) - Ferret::Index::Index.stub!(:new).and_return(mf) - Chef::SearchIndex.new.should be_kind_of(Chef::SearchIndex) - end - - it "should create a Ferret Indexer" do - mf = mock("Ferret::Index::Index", :null_object => true) - Ferret::Index::Index.should_receive(:new).and_return(mf) - Chef::SearchIndex.new - end -end - -describe Chef::SearchIndex, "create_index_object method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - @fakeobj = mock("ToIndex", :null_object => true) - @the_pigeon = { :index_name => "bird", :id => "pigeon" } - @fakeobj.stub!(:respond_to?).with(:to_index).and_return(true) - @fakeobj.stub!(:to_index).and_return(@the_pigeon) - Ferret::Index::Index.stub!(:new).and_return(@mf) - end - - def do_create_index_object - index = Chef::SearchIndex.new - index.create_index_object(@fakeobj) - end - - it "should call to_index if the passed object responds to it" do - @fakeobj.should_receive(:respond_to?).with(:to_index).and_return(true) - @fakeobj.should_receive(:to_index).and_return(@the_pigeon) - do_create_index_object - end - - it "should use a hash if the passed argument does not have to_index (but is a hash)" do - @fakeobj.stub!(:respond_to?).with(:to_index).and_return(false) - @fakeobj.should_receive(:kind_of?).with(Hash).and_return(true) - do_create_index_object - end - - it "should raise SearchIndex exception if the hash does not contain an :id field" do - @the_pigeon.delete(:id) - lambda { do_create_index_object }.should raise_error(Chef::Exception::SearchIndex) - end - - it "should raise SearchIndex exception if the hash does not contain an :index_name field" do - @the_pigeon.delete(:index_name) - lambda { do_create_index_object }.should raise_error(Chef::Exception::SearchIndex) - end - - it "should raise SearchIndex exception if the hash new_object cannot be indexed" do - @fakeobj.stub!(:respond_to?).and_return(false) - @fakeobj.stub!(:kind_of?).and_return(false) - lambda { do_create_index_object }.should raise_error(Chef::Exception::SearchIndex) - end - - it "should turn index hash keys in to symbols if it has strings" do - @the_pigeon["john"] = "and_yoko" - do_create_index_object.should have_key(:john) - end -end - -describe Chef::SearchIndex, "add method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - @fakeobj = mock("ToIndex", :null_object => true) - @the_pigeon = { :index_name => "bird", :id => "pigeon" } - @fakeobj.stub!(:respond_to?).with(:to_index).and_return(true) - @fakeobj.stub!(:to_index).and_return(@the_pigeon) - Ferret::Index::Index.stub!(:new).and_return(@mf) - end - - def do_add - index = Chef::SearchIndex.new - index.add(@fakeobj) - end - - it "should send the resulting hash to the index" do - @mf.should_receive(:add_document).with(@the_pigeon) - do_add - end -end - -describe Chef::SearchIndex, "delete method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - @fakeobj = mock("ToIndex", :null_object => true) - @the_pigeon = { :index_name => "bird", :id => "pigeon" } - @fakeobj.stub!(:respond_to?).with(:to_index).and_return(true) - @fakeobj.stub!(:to_index).and_return(@the_pigeon) - Ferret::Index::Index.stub!(:new).and_return(@mf) - end - - def do_delete(object) - index = Chef::SearchIndex.new - index.delete(object) - end - - it "should delete the resulting hash to the index" do - @mf.should_receive(:delete).with(@the_pigeon[:id]) - do_delete(@fakeobj) - end -end - -describe Chef::SearchIndex, "commit method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - Ferret::Index::Index.stub!(:new).and_return(@mf) - end - - it "should commit index to disk" do - @mf.should_receive(:commit) - Chef::SearchIndex.new.commit - end -end diff --git a/spec/unit/search_spec.rb b/spec/unit/search_spec.rb deleted file mode 100644 index 94e3560a23..0000000000 --- a/spec/unit/search_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) - -describe Chef::Search, "initialize method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - Ferret::Index::Index.stub!(:new).and_return(@mf) - end - - it "should build a Chef::Search object" do - Chef::Search.new.should be_a_kind_of(Chef::Search) - end - - it "should build a Ferret search backend" do - Ferret::Index::Index.should_receive(:new).and_return(@mf) - Chef::Search.new - end -end - -describe Chef::Search, "search method" do - before(:each) do - @mf = mock("Ferret::Index::Index", :null_object => true) - end - - def do_search(type, query, &block) - Ferret::Index::Index.stub!(:new).and_return(@mf) - cs = Chef::Search.new - if Kernel.block_given? - cs.search(type, query, &block) - else - cs.search(type, query) - end - end - - it "should build the search query from the type and query provided" do - Ferret::Index::Index.stub!(:new).and_return(@mf) - cs = Chef::Search.new - cs.should_receive(:build_search_query).with(:node, "tag:monkey") - cs.search(:node, "tag:monkey") - end - - it "should call search_each with the custom block if a block is given" do - cp = lambda { |n,u| "noting to do here" } - @mf.should_receive(:search_each).with("index_name:node AND (tag:monkey)", { :limit => :all }, &cp) - do_search(:node, "tag:monkey", &cp) - end - - it "should call search_each if a block is not given" do - @mf.should_receive(:search_each).with("index_name:node AND (tag:monkey)", {:limit => :all}) - do_search(:node, "tag:monkey") - end - - it "should return the search results" do - @mf.should_receive(:search_each).with("index_name:node AND (tag:monkey)", :limit => :all).and_return(true) - do_search(:node, "tag:monkey").should eql([]) - end -end
\ No newline at end of file |