diff options
Diffstat (limited to 'spec/unit/resource')
50 files changed, 4019 insertions, 0 deletions
diff --git a/spec/unit/resource/apt_package_spec.rb b/spec/unit/resource/apt_package_spec.rb new file mode 100644 index 0000000000..795ffc6fc4 --- /dev/null +++ b/spec/unit/resource/apt_package_spec.rb @@ -0,0 +1,43 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::AptPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::AptPackage.new("foo") + end + + it "should return a Chef::Resource::AptPackage" do + @resource.should be_a_kind_of(Chef::Resource::AptPackage) + end + + it "should set the resource_name to :apt_package" do + @resource.resource_name.should eql(:apt_package) + end + + it "should set the provider to Chef::Provider::Package::Apt" do + @resource.provider.should eql(Chef::Provider::Package::Apt) + end + + it "should support default_release" do + @resource.default_release("lenny-backports") + @resource.default_release.should eql("lenny-backports") + end +end diff --git a/spec/unit/resource/bash_spec.rb b/spec/unit/resource/bash_spec.rb new file mode 100644 index 0000000000..c7f31e1de6 --- /dev/null +++ b/spec/unit/resource/bash_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 diff --git a/spec/unit/resource/breakpoint_spec.rb b/spec/unit/resource/breakpoint_spec.rb new file mode 100644 index 0000000000..8eaabb546d --- /dev/null +++ b/spec/unit/resource/breakpoint_spec.rb @@ -0,0 +1,43 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Breakpoint do + + before do + @breakpoint = Chef::Resource::Breakpoint.new + end + + it "allows the action :break" do + @breakpoint.allowed_actions.should include(:break) + end + + it "defaults to the break action" do + @breakpoint.action.should == "break" + end + + it "names itself after the line number of the file where it's created" do + @breakpoint.name.should match(/breakpoint_spec\.rb\:[\d]{2}\:in \`new\'$/) + end + + it "uses the breakpoint provider" do + @breakpoint.provider.should == Chef::Provider::Breakpoint + end + +end diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb new file mode 100644 index 0000000000..54def9a49d --- /dev/null +++ b/spec/unit/resource/chef_gem_spec.rb @@ -0,0 +1,49 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Bryan McLellan <btm@loftninjas.org> +# Copyright:: Copyright (c) 2008, 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::ChefGem, "initialize" do + + before(:each) do + @resource = Chef::Resource::ChefGem.new("foo") + end + + it "should return a Chef::Resource::ChefGem" do + @resource.should be_a_kind_of(Chef::Resource::ChefGem) + end + + it "should set the resource_name to :chef_gem" do + @resource.resource_name.should eql(:chef_gem) + end + + it "should set the provider to Chef::Provider::Package::Rubygems" do + @resource.provider.should eql(Chef::Provider::Package::Rubygems) + end +end + +describe Chef::Resource::ChefGem, "gem_binary" do + before(:each) do + @resource = Chef::Resource::ChefGem.new("foo") + end + + it "should raise an exception when gem_binary is set" do + lambda { @resource.gem_binary("/lol/cats/gem") }.should raise_error(ArgumentError) + end +end diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb new file mode 100644 index 0000000000..1be7bcea71 --- /dev/null +++ b/spec/unit/resource/conditional_spec.rb @@ -0,0 +1,147 @@ +# +# Author:: Daniel DeLeo (<dan@opscode.com>) +# Copyright:: Copyright (c) 2011 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' +require 'ostruct' + +describe Chef::Resource::Conditional do + before do + Mixlib::ShellOut.any_instance.stub(:run_command).and_return(nil) + @status = OpenStruct.new(:success? => true) + Mixlib::ShellOut.any_instance.stub(:status).and_return(@status) + end + + describe "when created as an `only_if`" do + describe "after running a successful command" do + before do + @conditional = Chef::Resource::Conditional.only_if("true") + end + + it "indicates that resource convergence should continue" do + @conditional.continue?.should be_true + end + end + + describe "after running a negative/false command" do + before do + @status.send("success?=", false) + @conditional = Chef::Resource::Conditional.only_if("false") + end + + it "indicates that resource convergence should not continue" do + @conditional.continue?.should be_false + end + end + + describe 'after running a command which timed out' do + before do + @conditional = Chef::Resource::Conditional.only_if("false") + @conditional.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) + end + + it 'indicates that resource convergence should not continue' do + @conditional.continue?.should be_false + end + + it 'should log a warning' do + Chef::Log.should_receive(:warn).with("Command 'false' timed out") + @conditional.continue? + end + end + + describe "after running a block that returns a truthy value" do + before do + @conditional = Chef::Resource::Conditional.only_if { Object.new } + end + + it "indicates that resource convergence should continue" do + @conditional.continue?.should be_true + end + end + + describe "after running a block that returns a falsey value" do + before do + @conditional = Chef::Resource::Conditional.only_if { nil } + end + + it "indicates that resource convergence should not continue" do + @conditional.continue?.should be_false + end + end + end + + describe "when created as a `not_if`" do + describe "after running a successful/true command" do + before do + @conditional = Chef::Resource::Conditional.not_if("true") + end + + it "indicates that resource convergence should not continue" do + @conditional.continue?.should be_false + end + end + + describe "after running a failed/false command" do + before do + @status.send("success?=", false) + @conditional = Chef::Resource::Conditional.not_if("false") + end + + it "indicates that resource convergence should continue" do + @conditional.continue?.should be_true + end + end + + describe 'after running a command which timed out' do + before do + @conditional = Chef::Resource::Conditional.not_if("false") + @conditional.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) + end + + it 'indicates that resource convergence should continue' do + @conditional.continue?.should be_true + end + + it 'should log a warning' do + Chef::Log.should_receive(:warn).with("Command 'false' timed out") + @conditional.continue? + end + end + + describe "after running a block that returns a truthy value" do + before do + @conditional = Chef::Resource::Conditional.not_if { Object.new } + end + + it "indicates that resource convergence should not continue" do + @conditional.continue?.should be_false + end + end + + describe "after running a block that returns a falsey value" do + before do + @conditional = Chef::Resource::Conditional.not_if { nil } + end + + it "indicates that resource convergence should continue" do + @conditional.continue?.should be_true + end + end + end + +end diff --git a/spec/unit/resource/cookbook_file_spec.rb b/spec/unit/resource/cookbook_file_spec.rb new file mode 100644 index 0000000000..d0408c251a --- /dev/null +++ b/spec/unit/resource/cookbook_file_spec.rb @@ -0,0 +1,89 @@ +# +# Author:: Daniel DeLeo (<dan@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2010 Opscode, Inc. +#p License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::CookbookFile do + before do + @cookbook_file = Chef::Resource::CookbookFile.new('sourcecode_tarball.tgz') + end + + it "uses the name parameter for the source parameter" do + @cookbook_file.name.should == 'sourcecode_tarball.tgz' + end + + it "has a source parameter" do + @cookbook_file.name('config_file.conf') + @cookbook_file.name.should == 'config_file.conf' + end + + it "defaults to a nil cookbook parameter (current cookbook will be used)" do + @cookbook_file.cookbook.should be_nil + end + + it "has a cookbook parameter" do + @cookbook_file.cookbook("munin") + @cookbook_file.cookbook.should == 'munin' + end + + it "sets the provider to Chef::Provider::CookbookFile" do + @cookbook_file.provider.should == Chef::Provider::CookbookFile + end + + describe "when it has a backup number, group, mode, owner, source, checksum, and cookbook on nix or path, rights, deny_rights, checksum on windows" do + before do + if Chef::Platform.windows? + @cookbook_file.path("C:/temp/origin/file.txt") + @cookbook_file.rights(:read, "Everyone") + @cookbook_file.deny_rights(:full_control, "Clumsy_Sam") + else + @cookbook_file.path("/tmp/origin/file.txt") + @cookbook_file.group("wheel") + @cookbook_file.mode("0664") + @cookbook_file.owner("root") + @cookbook_file.source("/tmp/foo.txt") + @cookbook_file.cookbook("/tmp/cookbooks/cooked.rb") + end + @cookbook_file.checksum("1" * 64) + end + + + it "describes the state" do + state = @cookbook_file.state + if Chef::Platform.windows? + puts state + state[:rights].should == [{:permissions => :read, :principals => "Everyone"}] + state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}] + else + state[:group].should == "wheel" + state[:mode].should == "0664" + state[:owner].should == "root" + end + state[:checksum].should == "1" * 64 + end + + it "returns the path as its identity" do + if Chef::Platform.windows? + @cookbook_file.identity.should == "C:/temp/origin/file.txt" + else + @cookbook_file.identity.should == "/tmp/origin/file.txt" + end + end + end +end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb new file mode 100644 index 0000000000..403ffb009b --- /dev/null +++ b/spec/unit/resource/cron_spec.rb @@ -0,0 +1,181 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2009 Bryan McLellan +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Cron do + + before(:each) do + @resource = Chef::Resource::Cron.new("cronify") + end + + it "should create a new Chef::Resource::Cron" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Cron) + end + + it "should have a name" do + @resource.name.should eql("cronify") + 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 :lolcat }.should raise_error(ArgumentError) + end + + it "should allow you to set a command" do + @resource.command "/bin/true" + @resource.command.should eql("/bin/true") + end + + it "should allow you to set a user" do + @resource.user "daemon" + @resource.user.should eql("daemon") + end + + it "should allow you to specify the minute" do + @resource.minute "30" + @resource.minute.should eql("30") + end + + it "should allow you to specify the hour" do + @resource.hour "6" + @resource.hour.should eql("6") + end + + it "should allow you to specify the day" do + @resource.day "10" + @resource.day.should eql("10") + end + + it "should allow you to specify the month" do + @resource.month "10" + @resource.month.should eql("10") + end + + it "should allow you to specify the weekday" do + @resource.weekday "2" + @resource.weekday.should eql("2") + end + + it "should allow you to specify the mailto variable" do + @resource.mailto "test@example.com" + @resource.mailto.should eql("test@example.com") + end + + it "should allow you to specify the path" do + @resource.path "/usr/bin:/usr/sbin" + @resource.path.should eql("/usr/bin:/usr/sbin") + end + + it "should allow you to specify the home directory" do + @resource.home "/root" + @resource.home.should eql("/root") + end + + it "should allow you to specify the shell to run the command with" do + @resource.shell "/bin/zsh" + @resource.shell.should eql("/bin/zsh") + end + + it "should allow you to specify environment variables hash" do + env = {"TEST" => "LOL"} + @resource.environment env + @resource.environment.should eql(env) + end + + it "should allow * for all time and date values" do + [ "minute", "hour", "day", "month", "weekday" ].each do |x| + @resource.send(x, "*").should eql("*") + end + end + + it "should allow ranges for all time and date values" do + [ "minute", "hour", "day", "month", "weekday" ].each do |x| + @resource.send(x, "1-2,5").should eql("1-2,5") + end + end + + it "should have a default value of * for all time and date values" do + [ "minute", "hour", "day", "month", "weekday" ].each do |x| + @resource.send(x).should eql("*") + end + end + + it "should have a default value of root for the user" do + @resource.user.should eql("root") + end + + it "should reject any minute over 59" do + lambda { @resource.minute "60" }.should raise_error(RangeError) + end + + it "should reject any hour over 23" do + lambda { @resource.hour "24" }.should raise_error(RangeError) + end + + it "should reject any day over 31" do + lambda { @resource.day "32" }.should raise_error(RangeError) + end + + it "should reject any month over 12" do + lambda { @resource.month "13" }.should raise_error(RangeError) + end + + it "should reject any weekday over 7" do + lambda { @resource.weekday "8" }.should raise_error(RangeError) + end + + it "should convert integer schedule values to a string" do + [ "minute", "hour", "day", "month", "weekday" ].each do |x| + @resource.send(x, 5).should eql("5") + end + end + + describe "when it has a time (minute, hour, day, month, weeekend) and user" do + before do + @resource.command("tackle") + @resource.minute("1") + @resource.hour("2") + @resource.day("3") + @resource.month("4") + @resource.weekday("5") + @resource.user("root") + end + + it "describes the state" do + state = @resource.state + state[:minute].should == "1" + state[:hour].should == "2" + state[:day].should == "3" + state[:month].should == "4" + state[:weekday].should == "5" + state[:user].should == "root" + end + + it "returns the command as its identity" do + @resource.identity.should == "tackle" + end + end +end diff --git a/spec/unit/resource/csh_spec.rb b/spec/unit/resource/csh_spec.rb new file mode 100644 index 0000000000..291c6ea745 --- /dev/null +++ b/spec/unit/resource/csh_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 diff --git a/spec/unit/resource/deploy_revision_spec.rb b/spec/unit/resource/deploy_revision_spec.rb new file mode 100644 index 0000000000..671ba9a1f6 --- /dev/null +++ b/spec/unit/resource/deploy_revision_spec.rb @@ -0,0 +1,47 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2009 Daniel DeLeo +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::DeployRevision do + + it "defaults to the revision deploy provider" do + @resource = Chef::Resource::DeployRevision.new("deploy _this_!") + @resource.provider.should == Chef::Provider::Deploy::Revision + end + + it "has a name of deploy_revision" do + @resource = Chef::Resource::DeployRevision.new("deploy _this_!") + @resource.resource_name.should == :deploy_revision + end + +end + +describe Chef::Resource::DeployBranch do + + it "defaults to the revision deploy provider" do + @resource = Chef::Resource::DeployBranch.new("deploy _this_!") + @resource.provider.should == Chef::Provider::Deploy::Revision + end + + it "has a name of deploy_branch" do + @resource = Chef::Resource::DeployBranch.new("deploy _this_!") + @resource.resource_name.should == :deploy_branch + end + +end diff --git a/spec/unit/resource/deploy_spec.rb b/spec/unit/resource/deploy_spec.rb new file mode 100644 index 0000000000..98c9fa1581 --- /dev/null +++ b/spec/unit/resource/deploy_spec.rb @@ -0,0 +1,259 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Deploy do + + class << self + def resource_has_a_string_attribute(attr_name) + it "has a String attribute for #{attr_name.to_s}" do + @resource.send(attr_name, "this is a string") + @resource.send(attr_name).should eql("this is a string") + lambda {@resource.send(attr_name, 8675309)}.should raise_error(ArgumentError) + end + end + + def resource_has_a_boolean_attribute(attr_name, opts={:defaults_to=>false}) + it "has a Boolean attribute for #{attr_name.to_s}" do + @resource.send(attr_name).should eql(opts[:defaults_to]) + @resource.send(attr_name, !opts[:defaults_to]) + @resource.send(attr_name).should eql( !opts[:defaults_to] ) + end + end + + def resource_has_a_callback_attribute(attr_name) + it "has a Callback attribute #{attr_name}" do + callback_block = lambda { :noop } + lambda {@resource.send(attr_name, &callback_block)}.should_not raise_error + @resource.send(attr_name).should == callback_block + callback_file = "path/to/callback.rb" + lambda {@resource.send(attr_name, callback_file)}.should_not raise_error + @resource.send(attr_name).should == callback_file + lambda {@resource.send(attr_name, :this_is_fail)}.should raise_error(ArgumentError) + end + end + end + + before do + @resource = Chef::Resource::Deploy.new("/my/deploy/dir") + end + + resource_has_a_string_attribute(:repo) + resource_has_a_string_attribute(:deploy_to) + resource_has_a_string_attribute(:role) + resource_has_a_string_attribute(:restart_command) + resource_has_a_string_attribute(:migration_command) + resource_has_a_string_attribute(:user) + resource_has_a_string_attribute(:group) + resource_has_a_string_attribute(:repository_cache) + resource_has_a_string_attribute(:copy_exclude) + resource_has_a_string_attribute(:revision) + resource_has_a_string_attribute(:remote) + resource_has_a_string_attribute(:git_ssh_wrapper) + resource_has_a_string_attribute(:svn_username) + resource_has_a_string_attribute(:svn_password) + resource_has_a_string_attribute(:svn_arguments) + resource_has_a_string_attribute(:svn_info_args) + + resource_has_a_boolean_attribute(:migrate, :defaults_to=>false) + resource_has_a_boolean_attribute(:enable_submodules, :defaults_to=>false) + resource_has_a_boolean_attribute(:shallow_clone, :defaults_to=>false) + + it "uses the first argument as the deploy directory" do + @resource.deploy_to.should eql("/my/deploy/dir") + end + + # For git, any revision, branch, tag, whatever is resolved to a SHA1 ref. + # For svn, the branch is included in the repo URL. + # Therefore, revision and branch ARE NOT SEPARATE THINGS + it "aliases #revision as #branch" do + @resource.branch "stable" + @resource.revision.should eql("stable") + end + + it "takes the SCM resource to use as a constant, and defaults to git" do + @resource.scm_provider.should eql(Chef::Provider::Git) + @resource.scm_provider Chef::Provider::Subversion + @resource.scm_provider.should eql(Chef::Provider::Subversion) + end + + it "allows scm providers to be set via symbol" do + @resource.scm_provider.should == Chef::Provider::Git + @resource.scm_provider :subversion + @resource.scm_provider.should == Chef::Provider::Subversion + end + + it "allows scm providers to be set via string" do + @resource.scm_provider.should == Chef::Provider::Git + @resource.scm_provider "subversion" + @resource.scm_provider.should == Chef::Provider::Subversion + end + + it "has a boolean attribute for svn_force_export defaulting to false" do + @resource.svn_force_export.should be_false + @resource.svn_force_export true + @resource.svn_force_export.should be_true + lambda {@resource.svn_force_export(10053)}.should raise_error(ArgumentError) + end + + it "takes arbitrary environment variables in a hash" do + @resource.environment "RAILS_ENV" => "production" + @resource.environment.should == {"RAILS_ENV" => "production"} + end + + it "takes string arguments to environment for backwards compat, setting RAILS_ENV, RACK_ENV, and MERB_ENV" do + @resource.environment "production" + @resource.environment.should == {"RAILS_ENV"=>"production", "RACK_ENV"=>"production","MERB_ENV"=>"production"} + end + + it "sets destination to $deploy_to/shared/$repository_cache" do + @resource.destination.should eql("/my/deploy/dir/shared/cached-copy") + end + + it "sets shared_path to $deploy_to/shared" do + @resource.shared_path.should eql("/my/deploy/dir/shared") + end + + it "sets current_path to $deploy_to/current" do + @resource.current_path.should eql("/my/deploy/dir/current") + end + + it "gets the current_path correct even if the shared_path is set (regression test)" do + @resource.shared_path + @resource.current_path.should eql("/my/deploy/dir/current") + end + + it "gives #depth as 5 if shallow clone is true, nil otherwise" do + @resource.depth.should be_nil + @resource.shallow_clone true + @resource.depth.should eql("5") + end + + it "aliases repo as repository" do + @resource.repository "git@github.com/opcode/cookbooks.git" + @resource.repo.should eql("git@github.com/opcode/cookbooks.git") + end + + it "aliases git_ssh_wrapper as ssh_wrapper" do + @resource.ssh_wrapper "git_my_repo.sh" + @resource.git_ssh_wrapper.should eql("git_my_repo.sh") + end + + it "has an Array attribute purge_before_symlink, default: log, tmp/pids, public/system" do + @resource.purge_before_symlink.should == %w{ log tmp/pids public/system } + @resource.purge_before_symlink %w{foo bar baz} + @resource.purge_before_symlink.should == %w{foo bar baz} + end + + it "has an Array attribute create_dirs_before_symlink, default: tmp, public, config" do + @resource.create_dirs_before_symlink.should == %w{tmp public config} + @resource.create_dirs_before_symlink %w{foo bar baz} + @resource.create_dirs_before_symlink.should == %w{foo bar baz} + end + + it 'has a Hash attribute symlinks, default: {"system" => "public/system", "pids" => "tmp/pids", "log" => "log"}' do + default = { "system" => "public/system", "pids" => "tmp/pids", "log" => "log"} + @resource.symlinks.should == default + @resource.symlinks "foo" => "bar/baz" + @resource.symlinks.should == {"foo" => "bar/baz"} + end + + it 'has a Hash attribute symlink_before_migrate, default "config/database.yml" => "config/database.yml"' do + @resource.symlink_before_migrate.should == {"config/database.yml" => "config/database.yml"} + @resource.symlink_before_migrate "wtf?" => "wtf is going on" + @resource.symlink_before_migrate.should == {"wtf?" => "wtf is going on"} + end + + resource_has_a_callback_attribute :before_migrate + resource_has_a_callback_attribute :before_symlink + resource_has_a_callback_attribute :before_restart + resource_has_a_callback_attribute :after_restart + + it "aliases restart_command as restart" do + @resource.restart "foobaz" + @resource.restart_command.should == "foobaz" + end + + it "takes a block for the restart parameter" do + restart_like_this = lambda {p :noop} + @resource.restart(&restart_like_this) + @resource.restart.should == restart_like_this + end + + it "defaults to using the Deploy::Timestamped provider" do + @resource.provider.should == Chef::Provider::Deploy::Timestamped + end + + it "allows providers to be set with a full class name" do + @resource.provider Chef::Provider::Deploy::Timestamped + @resource.provider.should == Chef::Provider::Deploy::Timestamped + end + + it "allows deploy providers to be set via symbol" do + @resource.provider :revision + @resource.provider.should == Chef::Provider::Deploy::Revision + end + + it "allows deploy providers to be set via string" do + @resource.provider "revision" + @resource.provider.should == Chef::Provider::Deploy::Revision + end + + it "defaults keep_releases to 5" do + @resource.keep_releases.should == 5 + end + + it "allows keep_releases to be set via integer" do + @resource.keep_releases 10 + @resource.keep_releases.should == 10 + end + + it "enforces a minimum keep_releases of 1" do + @resource.keep_releases 0 + @resource.keep_releases.should == 1 + end + + describe "when it has meta application root, revision, user, group, + scm provider, repository cache, environment, simlinks and migrate" do + before do + @resource.repository("http://uri.org") + @resource.deploy_to("/") + @resource.revision("1.2.3") + @resource.user("root") + @resource.group("pokemon") + @resource.scm_provider(Chef::Provider::Git) + @resource.repository_cache("cached-copy") + @resource.environment({"SUDO" => "TRUE"}) + @resource.symlinks({"system" => "public/system"}) + @resource.migrate(false) + + end + + it "describes its state" do + state = @resource.state + state[:deploy_to].should == "/" + state[:revision].should == "1.2.3" + end + + it "returns the repository URI as its identity" do + @resource.identity.should == "http://uri.org" + end + end + +end diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb new file mode 100644 index 0000000000..9b0c8242e6 --- /dev/null +++ b/spec/unit/resource/directory_spec.rb @@ -0,0 +1,82 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 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 + + 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 + + describe "when it has group, mode, and owner" do + before do + @resource.path("/tmp/foo/bar/") + @resource.group("wheel") + @resource.mode("0664") + @resource.owner("root") + end + + it "describes its state" do + state = @resource.state + state[:group].should == "wheel" + state[:mode].should == "0664" + state[:owner].should == "root" + end + + it "returns the directory path as its identity" do + @resource.identity.should == "/tmp/foo/bar/" + end + end +end diff --git a/spec/unit/resource/dpkg_package_spec.rb b/spec/unit/resource/dpkg_package_spec.rb new file mode 100644 index 0000000000..000908712f --- /dev/null +++ b/spec/unit/resource/dpkg_package_spec.rb @@ -0,0 +1,38 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::DpkgPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::DpkgPackage.new("foo") + end + + it "should return a Chef::Resource::DpkgPackage" do + @resource.should be_a_kind_of(Chef::Resource::DpkgPackage) + end + + it "should set the resource_name to :dpkg_package" do + @resource.resource_name.should eql(:dpkg_package) + end + + it "should set the provider to Chef::Provider::Package::Dpkg" do + @resource.provider.should eql(Chef::Provider::Package::Dpkg) + end +end diff --git a/spec/unit/resource/easy_install_package_spec.rb b/spec/unit/resource/easy_install_package_spec.rb new file mode 100644 index 0000000000..9682c8177b --- /dev/null +++ b/spec/unit/resource/easy_install_package_spec.rb @@ -0,0 +1,48 @@ +# +# Author:: Joe Williams (<joe@joetify.com>) +# Copyright:: Copyright (c) 2009 Joe Williams +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::EasyInstallPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::EasyInstallPackage.new("foo") + end + + it "should create a new Chef::Resource::EasyInstallPackage" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::EasyInstallPackage) + end + + it "should return a Chef::Resource::EasyInstallPackage" do + @resource.should be_a_kind_of(Chef::Resource::EasyInstallPackage) + end + + it "should set the resource_name to :easy_install_package" do + @resource.resource_name.should eql(:easy_install_package) + end + + it "should set the provider to Chef::Provider::Package::EasyInstall" do + @resource.provider.should eql(Chef::Provider::Package::EasyInstall) + end + + it "should allow you to set the easy_install_binary attribute" do + @resource.easy_install_binary "/opt/local/bin/easy_install" + @resource.easy_install_binary.should eql("/opt/local/bin/easy_install") + end +end diff --git a/spec/unit/resource/env_spec.rb b/spec/unit/resource/env_spec.rb new file mode 100644 index 0000000000..6862c669b2 --- /dev/null +++ b/spec/unit/resource/env_spec.rb @@ -0,0 +1,85 @@ +# +# Author:: Doug MacEachern (<dougm@vmware.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2010 VMware, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Env do + + before(:each) do + @resource = Chef::Resource::Env.new("FOO") + end + + it "should create a new Chef::Resource::Env" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Env) + end + + it "should have a name" do + @resource.name.should eql("FOO") + end + + it "should have a default action of 'create'" do + @resource.action.should eql(:create) + end + + { :create => false, :delete => false, :modify => false, :flibber => true }.each do |action,bad_value| + it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do + if bad_value + lambda { @resource.action action }.should raise_error(ArgumentError) + else + lambda { @resource.action action }.should_not raise_error(ArgumentError) + end + end + end + + it "should use the object name as the key_name by default" do + @resource.key_name.should eql("FOO") + end + + it "should accept a string as the env value via 'value'" do + lambda { @resource.value "bar" }.should_not raise_error(ArgumentError) + end + + it "should not accept a Hash for the env value via 'to'" do + lambda { @resource.value Hash.new }.should raise_error(ArgumentError) + end + + it "should allow you to set an env value via 'to'" do + @resource.value "bar" + @resource.value.should eql("bar") + end + + describe "when it has key name and value" do + before do + @resource.key_name("charmander") + @resource.value("level7") + @resource.delim("hi") + end + + it "describes its state" do + state = @resource.state + state[:value].should == "level7" + end + + it "returns the key name as its identity" do + @resource.identity.should == "charmander" + end + end + +end diff --git a/spec/unit/resource/erl_call_spec.rb b/spec/unit/resource/erl_call_spec.rb new file mode 100644 index 0000000000..ccad371723 --- /dev/null +++ b/spec/unit/resource/erl_call_spec.rb @@ -0,0 +1,81 @@ +# +# Author:: Joe Williams (<joe@joetify.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2009 Joe Williams +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::ErlCall do + + before(:each) do + @resource = Chef::Resource::ErlCall.new("fakey_fakerton") + end + + it "should create a new Chef::Resource::ErlCall" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::ErlCall) + end + + it "should have a resource name of :erl_call" do + @resource.resource_name.should eql(:erl_call) + end + + it "should have a default action of run" do + @resource.action.should eql("run") + end + + it "should accept run as an action" do + lambda { @resource.action :run }.should_not raise_error(ArgumentError) + end + + it "should allow you to set the code attribute" do + @resource.code "q()." + @resource.code.should eql("q().") + end + + it "should allow you to set the cookie attribute" do + @resource.cookie "nomnomnom" + @resource.cookie.should eql("nomnomnom") + end + + it "should allow you to set the distributed attribute" do + @resource.distributed true + @resource.distributed.should eql(true) + end + + it "should allow you to set the name_type attribute" do + @resource.name_type "sname" + @resource.name_type.should eql("sname") + end + + it "should allow you to set the node_name attribute" do + @resource.node_name "chef@erlang" + @resource.node_name.should eql("chef@erlang") + end + + describe "when it has cookie and node_name" do + before do + @resource.code("erl-call:function()") + @resource.cookie("cookie") + @resource.node_name("raster") + end + + it "returns the code as its identity" do + @resource.identity.should == "erl-call:function()" + end + end +end diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb new file mode 100644 index 0000000000..0dcdab7409 --- /dev/null +++ b/spec/unit/resource/execute_spec.rb @@ -0,0 +1,124 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 an array on instantiation, too" do + resource = Chef::Resource::Execute.new(%w{something else}) + resource.should be_a_kind_of(Chef::Resource) + resource.should be_a_kind_of(Chef::Resource::Execute) + resource.command.should eql(%w{something else}) + end + + it "should accept a string for the command to run" do + @resource.command "something" + @resource.command.should eql("something") + end + + it "should accept an array for the command to run" do + @resource.command %w{something else} + @resource.command.should eql(%w{something else}) + 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 "allows the environment to be specified with #env" do + @resource.should respond_to(:env) + 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 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 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 + + describe "when it has cwd, environment, group, path, return value, and a user" do + before do + @resource.command("grep") + @resource.cwd("/tmp/") + @resource.environment({ :one => :two }) + @resource.group("legos") + @resource.path(["/var/local/"]) + @resource.returns(1) + @resource.user("root") + end + + it "returns the command as its identity" do + @resource.identity.should == "grep" + end + end +end diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb new file mode 100644 index 0000000000..58a7bd68b3 --- /dev/null +++ b/spec/unit/resource/file_spec.rb @@ -0,0 +1,121 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::File do + + before(:each) do + @resource = Chef::Resource::File.new("fakey_fakerton") + 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 have a default content of nil" do + @resource.content.should be_nil + end + + it "should be set to back up 5 files by default" do + @resource.backup.should eql(5) + end + + it "should only accept strings for content" do + lambda { @resource.content 5 }.should raise_error(ArgumentError) + lambda { @resource.content :foo }.should raise_error(ArgumentError) + lambda { @resource.content "hello" => "there" }.should raise_error(ArgumentError) + lambda { @resource.content "hi" }.should_not raise_error(ArgumentError) + 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 a sha256 for checksum" do + lambda { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.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 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 + + describe "when it has a path, owner, group, mode, and checksum" do + before do + @resource.path("/tmp/foo.txt") + @resource.owner("root") + @resource.group("wheel") + @resource.mode("0644") + @resource.checksum("1" * 64) + end + + context "on unix", :unix_only do + it "describes its state" do + state = @resource.state + state[:owner].should == "root" + state[:group].should == "wheel" + state[:mode].should == "0644" + state[:checksum].should == "1" * 64 + end + end + + context "on windows", :windows_only do + # according to Chef::Resource::File, windows state attributes are rights + deny_rights + pending "it describes its state" + end + + it "returns the file path as its identity" do + @resource.identity.should == "/tmp/foo.txt" + end + + end + + describe "when access controls are set on windows", :windows_only => true do + before do + @resource.rights :read, "Everyone" + @resource.rights :full_control, "DOMAIN\User" + end + it "describes its state including windows ACL attributes" do + state = @resource.state + state[:rights].should == [ {:permissions => :read, :principals => "Everyone"}, + {:permissions => :full_control, :principals => "DOMAIN\User"} ] + end + end + +end diff --git a/spec/unit/resource/freebsd_package_spec.rb b/spec/unit/resource/freebsd_package_spec.rb new file mode 100644 index 0000000000..697f5fff06 --- /dev/null +++ b/spec/unit/resource/freebsd_package_spec.rb @@ -0,0 +1,39 @@ +# +# Author:: AJ Christensen (<aj@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::FreebsdPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::FreebsdPackage.new("foo") + end + + it "should return a Chef::Resource::FreebsdPackage" do + @resource.should be_a_kind_of(Chef::Resource::FreebsdPackage) + end + + it "should set the resource_name to :freebsd_package" do + @resource.resource_name.should eql(:freebsd_package) + end + + it "should set the provider to Chef::Provider::Package::freebsd" do + @resource.provider.should eql(Chef::Provider::Package::Freebsd) + end +end + diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb new file mode 100644 index 0000000000..2404afa03a --- /dev/null +++ b/spec/unit/resource/gem_package_spec.rb @@ -0,0 +1,49 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::GemPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::GemPackage.new("foo") + end + + it "should return a Chef::Resource::GemPackage" do + @resource.should be_a_kind_of(Chef::Resource::GemPackage) + end + + it "should set the resource_name to :gem_package" do + @resource.resource_name.should eql(:gem_package) + end + + it "should set the provider to Chef::Provider::Package::Rubygems" do + @resource.provider.should eql(Chef::Provider::Package::Rubygems) + end +end + +describe Chef::Resource::GemPackage, "gem_binary" do + before(:each) do + @resource = Chef::Resource::GemPackage.new("foo") + end + + it "should set the gem_binary variable to whatever is passed in" do + @resource.gem_binary("/opt/local/bin/gem") + @resource.gem_binary.should eql("/opt/local/bin/gem") + end +end diff --git a/spec/unit/resource/git_spec.rb b/spec/unit/resource/git_spec.rb new file mode 100644 index 0000000000..69b40ffd42 --- /dev/null +++ b/spec/unit/resource/git_spec.rb @@ -0,0 +1,46 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Git do + + before(:each) do + @git = Chef::Resource::Git.new("my awesome webapp") + end + + it "is a kind of Scm Resource" do + @git.should be_a_kind_of(Chef::Resource::Scm) + @git.should be_an_instance_of(Chef::Resource::Git) + end + + it "uses the git provider" do + @git.provider.should eql(Chef::Provider::Git) + end + + it "uses aliases revision as branch" do + @git.branch "HEAD" + @git.revision.should eql("HEAD") + end + + it "aliases revision as reference" do + @git.reference "v1.0 tag" + @git.revision.should eql("v1.0 tag") + end + +end diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb new file mode 100644 index 0000000000..7181750b1c --- /dev/null +++ b/spec/unit/resource/group_spec.rb @@ -0,0 +1,148 @@ +# +# Author:: AJ Christensen (<aj@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>); +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Group, "initialize" do + before(:each) do + @resource = Chef::Resource::Group.new("admin") + end + + it "should create a new Chef::Resource::Group" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Group) + end + + it "should set the resource_name to :group" do + @resource.resource_name.should eql(:group) + end + + it "should set the group_name equal to the argument to initialize" do + @resource.group_name.should eql("admin") + end + + it "should default gid to nil" do + @resource.gid.should eql(nil) + end + + it "should default members to an empty array" do + @resource.members.should eql([]) + end + + it "should alias users to members, also an empty array" do + @resource.users.should eql([]) + end + + it "should set action to :create" do + @resource.action.should eql(:create) + end + + %w{create remove modify manage}.each do |action| + it "should allow action #{action}" do + @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) + end + end +end + +describe Chef::Resource::Group, "group_name" do + before(:each) do + @resource = Chef::Resource::Group.new("admin") + end + + it "should allow a string" do + @resource.group_name "pirates" + @resource.group_name.should eql("pirates") + end + + it "should not allow a hash" do + lambda { @resource.send(:group_name, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + end +end + +describe Chef::Resource::Group, "gid" do + before(:each) do + @resource = Chef::Resource::Group.new("admin") + end + + it "should allow an integer" do + @resource.gid 100 + @resource.gid.should eql(100) + end + + it "should not allow a hash" do + lambda { @resource.send(:gid, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + end +end + +describe Chef::Resource::Group, "members" do + before(:each) do + @resource = Chef::Resource::Group.new("admin") + end + + [ :users, :members].each do |method| + it "(#{method}) should allow and convert a string" do + @resource.send(method, "aj") + @resource.send(method).should eql(["aj"]) + end + + it "(#{method}) should allow an array" do + @resource.send(method, [ "aj", "adam" ]) + @resource.send(method).should eql( ["aj", "adam"] ) + end + + it "(#{method}) should not allow a hash" do + lambda { @resource.send(method, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + end + end +end + +describe Chef::Resource::Group, "append" do + before(:each) do + @resource = Chef::Resource::Group.new("admin") + end + + it "should default to false" do + @resource.append.should eql(false) + end + + it "should allow a boolean" do + @resource.append true + @resource.append.should eql(true) + end + + it "should not allow a hash" do + lambda { @resource.send(:gid, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + end + + describe "when it has members" do + before do + @resource.group_name("pokemon") + @resource.members(["blastoise", "pikachu"]) + end + + it "describes its state" do + state = @resource.state + state[:members].should eql(["blastoise", "pikachu"]) + end + + it "returns the group name as its identity" do + @resource.identity.should == "pokemon" + end + end +end diff --git a/spec/unit/resource/http_request_spec.rb b/spec/unit/resource/http_request_spec.rb new file mode 100644 index 0000000000..924cf66fc2 --- /dev/null +++ b/spec/unit/resource/http_request_spec.rb @@ -0,0 +1,59 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::HttpRequest do + + before(:each) do + @resource = Chef::Resource::HttpRequest.new("fakey_fakerton") + end + + it "should create a new Chef::Resource::HttpRequest" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::HttpRequest) + end + + it "should set url to a string" do + @resource.url "http://slashdot.org" + @resource.url.should eql("http://slashdot.org") + end + + it "should set the message to the name by default" do + @resource.message.should eql("fakey_fakerton") + end + + it "should set message to a string" do + @resource.message "monkeybars" + @resource.message.should eql("monkeybars") + end + + describe "when it has a message and headers" do + before do + @resource.url("http://www.trololol.net") + @resource.message("Get sum post brah.") + @resource.headers({"head" => "tail"}) + end + + it "returns the url as its identity" do + @resource.identity.should == "http://www.trololol.net" + end + end + +end diff --git a/spec/unit/resource/ifconfig_spec.rb b/spec/unit/resource/ifconfig_spec.rb new file mode 100644 index 0000000000..2aac130978 --- /dev/null +++ b/spec/unit/resource/ifconfig_spec.rb @@ -0,0 +1,46 @@ +# +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2009 Joe Williams +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Ifconfig do + + before(:each) do + @resource = Chef::Resource::Ifconfig.new("fakey_fakerton") + end + + describe "when it has target, hardware address, inet address, and a mask" do + before do + @resource.device("charmander") + @resource.target("team_rocket") + @resource.hwaddr("11.2223.223") + @resource.inet_addr("434.2343.23") + @resource.mask("255.255.545") + end + + it "describes its state" do + state = @resource.state + state[:inet_addr].should == "434.2343.23" + state[:mask].should == "255.255.545" + end + + it "returns the device as its identity" do + @resource.identity.should == "charmander" + end + end +end diff --git a/spec/unit/resource/ips_package_spec.rb b/spec/unit/resource/ips_package_spec.rb new file mode 100644 index 0000000000..92e62606de --- /dev/null +++ b/spec/unit/resource/ips_package_spec.rb @@ -0,0 +1,43 @@ +# +# Author:: Bryan McLellan <btm@opscode.com> +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::IpsPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::IpsPackage.new("crypto/gnupg") + end + + it "should return a Chef::Resource::IpsPackage" do + @resource.should be_a_kind_of(Chef::Resource::IpsPackage) + end + + it "should set the resource_name to :ips_package" do + @resource.resource_name.should eql(:ips_package) + end + + it "should set the provider to Chef::Provider::Package::Ips" do + @resource.provider.should eql(Chef::Provider::Package::Ips) + end + + it "should support accept_license" do + @resource.accept_license(true) + @resource.accept_license.should eql(true) + end +end diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb new file mode 100644 index 0000000000..279a5b4e77 --- /dev/null +++ b/spec/unit/resource/link_spec.rb @@ -0,0 +1,118 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 + + { :create => false, :delete => false, :blues => true }.each do |action,bad_value| + it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do + if bad_value + lambda { @resource.action action }.should raise_error(ArgumentError) + else + lambda { @resource.action action }.should_not raise_error(ArgumentError) + end + end + end + + it "should use the object name as the target_file by default" do + @resource.target_file.should eql("fakey_fakerton") + end + + it "should accept a string as the link source via 'to'" do + lambda { @resource.to "/tmp" }.should_not raise_error(ArgumentError) + end + + it "should not accept a Hash for the link source via 'to'" do + lambda { @resource.to Hash.new }.should raise_error(ArgumentError) + end + + it "should allow you to set a link source via 'to'" do + @resource.to "/tmp/foo" + @resource.to.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 + + 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 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 + + describe "when it has to, link_type, owner, and group" do + before do + @resource.target_file("/var/target.tar") + @resource.to("/to/dir/file.tar") + @resource.link_type(:symbolic) + @resource.owner("root") + @resource.group("0664") + end + + it "describes its state" do + state = @resource.state + state[:to].should == "/to/dir/file.tar" + state[:owner].should == "root" + state[:group].should == "0664" + end + + it "returns the target file as its identity" do + @resource.identity.should == "/var/target.tar" + end + end +end diff --git a/spec/unit/resource/log_spec.rb b/spec/unit/resource/log_spec.rb new file mode 100644 index 0000000000..bc5ac13078 --- /dev/null +++ b/spec/unit/resource/log_spec.rb @@ -0,0 +1,61 @@ +# +# Author:: Cary Penniman (<cary@rightscale.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Log do + + before(:each) do + @log_str = "this is my string to log" + @resource = Chef::Resource::Log.new(@log_str) + end + + it "should create a new Chef::Resource::Log" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Log) + end + + it "should have a name of log" do + @resource.resource_name.should == :log + end + + it "should allow you to set a log string" do + @resource.name.should == @log_str + end + + it "should accept a vaild level option" do + @resource.level :debug + @resource.level :info + @resource.level :warn + @resource.level :error + @resource.level :fatal + lambda { @resource.level :unsupported }.should raise_error(ArgumentError) + end + + describe "when the identity is defined" do + before do + @resource = Chef::Resource::Log.new("ery day I'm loggin-in") + end + + it "returns the log string as its identity" do + @resource.identity.should == "ery day I'm loggin-in" + end + end +end + diff --git a/spec/unit/resource/macports_package_spec.rb b/spec/unit/resource/macports_package_spec.rb new file mode 100644 index 0000000000..7420fafeb5 --- /dev/null +++ b/spec/unit/resource/macports_package_spec.rb @@ -0,0 +1,37 @@ +# +# Author:: David Balatero (<dbalatero@gmail.com>) +# Copyright:: Copyright (c) 2009 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::MacportsPackage, "initialize" do + before(:each) do + @resource = Chef::Resource::MacportsPackage.new("foo") + end + + it "should return a Chef::Resource::MacportsPackage" do + @resource.should be_a_kind_of(Chef::Resource::MacportsPackage) + end + + it "should set the resource_name to :macports_package" do + @resource.resource_name.should eql(:macports_package) + end + + it "should set the provider to Chef::Provider::Package::Macports" do + @resource.provider.should eql(Chef::Provider::Package::Macports) + end +end diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb new file mode 100644 index 0000000000..c4e6704ceb --- /dev/null +++ b/spec/unit/resource/mdadm_spec.rb @@ -0,0 +1,102 @@ +# +# Author:: Joe Williams (<joe@joetify.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2009 Joe Williams +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Mdadm do + + before(:each) do + @resource = Chef::Resource::Mdadm.new("fakey_fakerton") + end + + it "should create a new Chef::Resource::Mdadm" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Mdadm) + end + + it "should have a resource name of :mdadm" do + @resource.resource_name.should eql(:mdadm) + end + + it "should have a default action of create" do + @resource.action.should eql(:create) + end + + it "should accept create, assemble, stop as actions" do + lambda { @resource.action :create }.should_not raise_error(ArgumentError) + lambda { @resource.action :assemble }.should_not raise_error(ArgumentError) + lambda { @resource.action :stop }.should_not raise_error(ArgumentError) + end + + it "should allow you to set the raid_device attribute" do + @resource.raid_device "/dev/md3" + @resource.raid_device.should eql("/dev/md3") + end + + it "should allow you to set the chunk attribute" do + @resource.chunk 256 + @resource.chunk.should eql(256) + end + + it "should allow you to set the level attribute" do + @resource.level 1 + @resource.level.should eql(1) + end + + it "should allow you to set the metadata attribute" do + @resource.metadata "1.2" + @resource.metadata.should eql("1.2") + end + + it "should allow you to set the bitmap attribute" do + @resource.metadata "internal" + @resource.metadata.should eql("internal") + end + + it "should allow you to set the devices attribute" do + @resource.devices ["/dev/sda", "/dev/sdb"] + @resource.devices.should eql(["/dev/sda", "/dev/sdb"]) + end + + it "should allow you to set the exists attribute" do + @resource.exists true + @resource.exists.should eql(true) + end + + describe "when it has devices, level, and chunk" do + before do + @resource.raid_device("raider") + @resource.devices(["device1", "device2"]) + @resource.level(1) + @resource.chunk(42) + end + + it "describes its state" do + state = @resource.state + state[:devices].should eql(["device1", "device2"]) + state[:level].should == 1 + state[:chunk].should == 42 + end + + it "returns the raid device as its identity" do + @resource.identity.should == "raider" + end + end + +end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb new file mode 100644 index 0000000000..498f33a7ba --- /dev/null +++ b/spec/unit/resource/mount_spec.rb @@ -0,0 +1,158 @@ +# +# Author:: Joshua Timberman (<joshua@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2009 Opscode, Inc +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Mount do + before(:each) do + @resource = Chef::Resource::Mount.new("filesystem") + end + + it "should create a new Chef::Resource::Mount" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Mount) + end + + it "should have a name" do + @resource.name.should eql("filesystem") + end + + it "should set mount_point to the name" do + @resource.mount_point.should eql("filesystem") + end + + it "should have a default action of mount" do + @resource.action.should eql(:mount) + end + + it "should accept mount, umount and remount as actions" do + lambda { @resource.action :mount }.should_not raise_error(ArgumentError) + lambda { @resource.action :umount }.should_not raise_error(ArgumentError) + lambda { @resource.action :remount }.should_not raise_error(ArgumentError) + lambda { @resource.action :brooklyn }.should raise_error(ArgumentError) + end + + it "should allow you to set the device attribute" do + @resource.device "/dev/sdb3" + @resource.device.should eql("/dev/sdb3") + end + + it "should allow you to set the fstype attribute" do + @resource.fstype "nfs" + @resource.fstype.should eql("nfs") + end + + it "should allow you to set the dump attribute" do + @resource.dump 1 + @resource.dump.should eql(1) + end + + it "should allow you to set the pass attribute" do + @resource.pass 1 + @resource.pass.should eql(1) + end + + it "should set the options attribute to defaults" do + @resource.options.should eql(["defaults"]) + end + + it "should allow options to be sent as a string, and convert to array" do + @resource.options "rw,noexec" + @resource.options.should be_a_kind_of(Array) + end + + it "should allow options attribute as an array" do + @resource.options ["ro", "nosuid"] + @resource.options.should be_a_kind_of(Array) + end + + it "should accept true for mounted" do + @resource.mounted(true) + @resource.mounted.should eql(true) + end + + it "should accept false for mounted" do + @resource.mounted(false) + @resource.mounted.should eql(false) + end + + it "should set mounted to false by default" do + @resource.mounted.should eql(false) + end + + it "should not accept a string for mounted" do + lambda { @resource.mounted("poop") }.should raise_error(ArgumentError) + end + + it "should accept true for enabled" do + @resource.enabled(true) + @resource.enabled.should eql(true) + end + + it "should accept false for enabled" do + @resource.enabled(false) + @resource.enabled.should eql(false) + end + + it "should set enabled to false by default" do + @resource.enabled.should eql(false) + end + + it "should not accept a string for enabled" do + lambda { @resource.enabled("poop") }.should raise_error(ArgumentError) + end + + it "should default all feature support to false" do + support_hash = { :remount => false } + @resource.supports.should == support_hash + end + + it "should allow you to set feature support as an array" do + support_array = [ :remount ] + support_hash = { :remount => true } + @resource.supports(support_array) + @resource.supports.should == support_hash + end + + it "should allow you to set feature support as a hash" do + support_hash = { :remount => true } + @resource.supports(support_hash) + @resource.supports.should == support_hash + end + + describe "when it has mount point, device type, and fstype" do + before do + @resource.device("charmander") + @resource.mount_point("123.456") + @resource.device_type(:device) + @resource.fstype("ranked") + end + + it "describes its state" do + state = @resource.state + state[:mount_point].should == "123.456" + state[:device_type].should eql(:device) + state[:fstype].should == "ranked" + end + + it "returns the device as its identity" do + @resource.identity.should == "charmander" + end + end +end diff --git a/spec/unit/resource/ohai_spec.rb b/spec/unit/resource/ohai_spec.rb new file mode 100644 index 0000000000..82df61e509 --- /dev/null +++ b/spec/unit/resource/ohai_spec.rb @@ -0,0 +1,62 @@ +# +# Author:: Michael Leinartas (<mleinartas@gmail.com>) +# Copyright:: Copyright (c) 2010 Michael Leinartas +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Ohai do + + before(:each) do + @resource = Chef::Resource::Ohai.new("ohai_reload") + end + + it "should create a new Chef::Resource::Ohai" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Ohai) + end + + it "should have a resource name of :ohai" do + @resource.resource_name.should eql(:ohai) + end + + it "should have a default action of create" do + @resource.action.should eql(:reload) + end + + it "should allow you to set the plugin attribute" do + @resource.plugin "passwd" + @resource.plugin.should eql("passwd") + end + + describe "when it has a plugin value" do + before do + @resource.name("test") + @resource.plugin("passwd") + end + + it "describes its state" do + state = @resource.state + state[:plugin].should == "passwd" + end + + it "returns the name as its identity" do + @resource.identity.should == "test" + end + end + + +end diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb new file mode 100644 index 0000000000..3f9cc7a408 --- /dev/null +++ b/spec/unit/resource/package_spec.rb @@ -0,0 +1,80 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 + + it "should accept a string for the options" do + @resource.options "something" + @resource.options.should eql("something") + end + + describe "when it has a package_name and version" do + before do + @resource.package_name("tomcat") + @resource.version("10.9.8") + @resource.options("-al") + end + + it "describes its state" do + state = @resource.state + state[:version].should == "10.9.8" + state[:options].should == "-al" + end + + it "returns the file path as its identity" do + @resource.identity.should == "tomcat" + end + + end +end diff --git a/spec/unit/resource/pacman_package_spec.rb b/spec/unit/resource/pacman_package_spec.rb new file mode 100644 index 0000000000..53ecd296c9 --- /dev/null +++ b/spec/unit/resource/pacman_package_spec.rb @@ -0,0 +1,38 @@ +# +# Author:: Jan Zimmek (<jan.zimmek@web.de>) +# Copyright:: Copyright (c) 2010 Jan Zimmek +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::PacmanPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::PacmanPackage.new("foo") + end + + it "should return a Chef::Resource::PacmanPackage" do + @resource.should be_a_kind_of(Chef::Resource::PacmanPackage) + end + + it "should set the resource_name to :pacman_package" do + @resource.resource_name.should eql(:pacman_package) + end + + it "should set the provider to Chef::Provider::Package::Pacman" do + @resource.provider.should eql(Chef::Provider::Package::Pacman) + end +end diff --git a/spec/unit/resource/perl_spec.rb b/spec/unit/resource/perl_spec.rb new file mode 100644 index 0000000000..f0313e6fb9 --- /dev/null +++ b/spec/unit/resource/perl_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 diff --git a/spec/unit/resource/portage_package_spec.rb b/spec/unit/resource/portage_package_spec.rb new file mode 100644 index 0000000000..da086d95ba --- /dev/null +++ b/spec/unit/resource/portage_package_spec.rb @@ -0,0 +1,38 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) + +describe Chef::Resource::PortagePackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::PortagePackage.new("foo") + end + + it "should return a Chef::Resource::PortagePackage" do + @resource.should be_a_kind_of(Chef::Resource::PortagePackage) + end + + it "should set the resource_name to :portage_package" do + @resource.resource_name.should eql(:portage_package) + end + + it "should set the provider to Chef::Provider::Package::Portage" do + @resource.provider.should eql(Chef::Provider::Package::Portage) + end +end diff --git a/spec/unit/resource/python_spec.rb b/spec/unit/resource/python_spec.rb new file mode 100644 index 0000000000..ff9547db9a --- /dev/null +++ b/spec/unit/resource/python_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb new file mode 100644 index 0000000000..e4fa8fc4e3 --- /dev/null +++ b/spec/unit/resource/remote_directory_spec.rb @@ -0,0 +1,97 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 have the basename of the remote directory resource as the default source" do + @resource.source.should eql("dunk") + 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 + + describe "when it has cookbook, files owner, files mode, and source" do + before do + @resource.path("/var/path/") + @resource.cookbook("pokemon.rb") + @resource.files_owner("root") + @resource.files_group("supergroup") + @resource.files_mode("0664") + @resource.source("/var/source/") + end + + it "describes its state" do + state = @resource.state + state[:files_owner].should == "root" + state[:files_group].should == "supergroup" + state[:files_mode].should == "0664" + end + + it "returns the path as its identity" do + @resource.identity.should == "/var/path/" + end + end +end diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb new file mode 100644 index 0000000000..d91f80d1a7 --- /dev/null +++ b/spec/unit/resource/remote_file_spec.rb @@ -0,0 +1,123 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::RemoteFile do + + before(:each) do + @resource = Chef::Resource::RemoteFile.new("fakey_fakerton") + end + + describe "initialize" do + 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 + end + + it "says its provider is RemoteFile when the source is an absolute URI" do + @resource.source("http://www.google.com/robots.txt") + @resource.provider.should == Chef::Provider::RemoteFile + Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::RemoteFile + end + + + describe "source" do + it "does not have a default value for 'source'" do + @resource.source.should be_nil + end + + it "should accept a URI for the remote file source" do + @resource.source "http://opscode.com/" + @resource.source.should eql([ "http://opscode.com/" ]) + end + + it "should accept an array of URIs for the remote file source" do + @resource.source([ "http://opscode.com/", "http://puppetlabs.com/" ]) + @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + end + + it "should accept an multiple URIs as arguments for the remote file source" do + @resource.source("http://opscode.com/", "http://puppetlabs.com/") + @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + end + + it "does not accept a non-URI as the source" do + lambda { @resource.source("not-a-uri") }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI) + end + + it "should raise and exception when source is an empty array" do + lambda { @resource.source([]) }.should raise_error(ArgumentError) + end + + end + + describe "checksum" do + it "should accept a string for the checksum object" do + @resource.checksum "asdf" + @resource.checksum.should eql("asdf") + end + + it "should default to nil" do + @resource.checksum.should == nil + end + end + + describe "when it has group, mode, owner, source, and checksum" do + before do + if Chef::Platform.windows? + @resource.path("C:/temp/origin/file.txt") + @resource.rights(:read, "Everyone") + @resource.deny_rights(:full_control, "Clumsy_Sam") + else + @resource.path("/this/path/") + @resource.group("pokemon") + @resource.mode("0664") + @resource.owner("root") + end + @resource.source("https://www.google.com/images/srpr/logo3w.png") + @resource.checksum("1"*26) + end + + it "describes its state" do + state = @resource.state + if Chef::Platform.windows? + puts state + state[:rights].should == [{:permissions => :read, :principals => "Everyone"}] + state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}] + else + state[:group].should == "pokemon" + state[:mode].should == "0664" + state[:owner].should == "root" + state[:checksum].should == "1"*26 + end + end + + it "returns the path as its identity" do + if Chef::Platform.windows? + @resource.identity.should == "C:/temp/origin/file.txt" + else + @resource.identity.should == "/this/path/" + end + end + end + +end diff --git a/spec/unit/resource/route_spec.rb b/spec/unit/resource/route_spec.rb new file mode 100644 index 0000000000..54d5275411 --- /dev/null +++ b/spec/unit/resource/route_spec.rb @@ -0,0 +1,107 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Bryan McLellan +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Route do + + before(:each) do + @resource = Chef::Resource::Route.new("10.0.0.10") + end + + it "should create a new Chef::Resource::Route" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::Route) + end + + it "should have a name" do + @resource.name.should eql("10.0.0.10") + end + + it "should have a default action of 'add'" do + @resource.action.should eql(:add) + end + + it "should accept add or delete for action" do + lambda { @resource.action :add }.should_not raise_error(ArgumentError) + lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :lolcat }.should raise_error(ArgumentError) + end + + it "should use the object name as the target by default" do + @resource.target.should eql("10.0.0.10") + end + + it "should allow you to specify the netmask" do + @resource.netmask "255.255.255.0" + @resource.netmask.should eql("255.255.255.0") + end + + it "should allow you to specify the gateway" do + @resource.gateway "10.0.0.1" + @resource.gateway.should eql("10.0.0.1") + end + + it "should allow you to specify the metric" do + @resource.metric 10 + @resource.metric.should eql(10) + end + + it "should allow you to specify the device" do + @resource.device "eth0" + @resource.device.should eql("eth0") + end + + it "should allow you to specify the route type" do + @resource.route_type "host" + @resource.route_type.should eql(:host) + end + + it "should default to a host route type" do + @resource.route_type.should eql(:host) + end + + it "should accept a net route type" do + @resource.route_type :net + @resource.route_type.should eql(:net) + end + + it "should reject any other route_type but :host and :net" do + lambda { @resource.route_type "lolcat" }.should raise_error(ArgumentError) + end + + describe "when it has netmask, gateway, and device" do + before do + @resource.target("charmander") + @resource.netmask("lemask") + @resource.gateway("111.111.111") + @resource.device("forcefield") + end + + it "describes its state" do + state = @resource.state + state[:netmask].should == "lemask" + state[:gateway].should == "111.111.111" + end + + it "returns the target as its identity" do + @resource.identity.should == "charmander" + end + end +end diff --git a/spec/unit/resource/rpm_package_spec.rb b/spec/unit/resource/rpm_package_spec.rb new file mode 100644 index 0000000000..d59dc6b29c --- /dev/null +++ b/spec/unit/resource/rpm_package_spec.rb @@ -0,0 +1,38 @@ +# +# Author:: Thomas Bishop (<bishop.thomas@gmail.com>) +# Copyright:: Copyright (c) 2010 Thomas Bishop +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::RpmPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::RpmPackage.new("foo") + end + + it "should return a Chef::Resource::RpmPackage" do + @resource.should be_a_kind_of(Chef::Resource::RpmPackage) + end + + it "should set the resource_name to :rpm_package" do + @resource.resource_name.should eql(:rpm_package) + end + + it "should set the provider to Chef::Provider::Package::Rpm" do + @resource.provider.should eql(Chef::Provider::Package::Rpm) + end +end diff --git a/spec/unit/resource/ruby_block_spec.rb b/spec/unit/resource/ruby_block_spec.rb new file mode 100644 index 0000000000..637d4fe34d --- /dev/null +++ b/spec/unit/resource/ruby_block_spec.rb @@ -0,0 +1,61 @@ +# +# Author:: AJ Christensen (<aj@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::RubyBlock do + + before(:each) do + @resource = Chef::Resource::RubyBlock.new("fakey_fakerton") + end + + it "should create a new Chef::Resource::RubyBlock" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::RubyBlock) + end + + it "should have a default action of 'create'" do + @resource.action.should eql("run") + end + + it "should have a resource name of :ruby_block" do + @resource.resource_name.should eql(:ruby_block) + end + + it "should accept a ruby block/proc/.. for the 'block' parameter" do + @resource.block do + "foo" + end.call.should eql("foo") + end + + it "allows the action to be 'create'" do + @resource.action :create + @resource.action.should == [:create] + end + + describe "when it has been initialized with block code" do + before do + @resource.block_name("puts 'harrrr'") + end + + it "returns the block as its identity" do + @resource.identity.should == "puts 'harrrr'" + end + end +end diff --git a/spec/unit/resource/ruby_spec.rb b/spec/unit/resource/ruby_spec.rb new file mode 100644 index 0000000000..48dfd90898 --- /dev/null +++ b/spec/unit/resource/ruby_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 diff --git a/spec/unit/resource/scm_spec.rb b/spec/unit/resource/scm_spec.rb new file mode 100644 index 0000000000..488d335342 --- /dev/null +++ b/spec/unit/resource/scm_spec.rb @@ -0,0 +1,159 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Scm do + + before(:each) do + @resource = Chef::Resource::Scm.new("my awesome app") + end + + it "should be a SCM resource" do + @resource.should be_a_kind_of(Chef::Resource::Scm) + end + + it "supports :checkout, :export, :sync, :diff, and :log actions" do + @resource.allowed_actions.should include(:checkout) + @resource.allowed_actions.should include(:export) + @resource.allowed_actions.should include(:sync) + @resource.allowed_actions.should include(:diff) + @resource.allowed_actions.should include(:log) + end + + it "takes the destination path as a string" do + @resource.destination "/path/to/deploy/dir" + @resource.destination.should eql("/path/to/deploy/dir") + end + + it "takes a string for the repository URL" do + @resource.repository "git://github.com/opscode/chef.git" + @resource.repository.should eql("git://github.com/opscode/chef.git") + end + + it "takes a string for the revision" do + @resource.revision "abcdef" + @resource.revision.should eql("abcdef") + end + + it "defaults to the ``HEAD'' revision" do + @resource.revision.should eql("HEAD") + end + + it "takes a string for the user to run as" do + @resource.user "dr_deploy" + @resource.user.should eql("dr_deploy") + end + + it "also takes an integer for the user to run as" do + @resource.user 0 + @resource.user.should eql(0) + end + + it "takes a string for the group to run as, defaulting to nil" do + @resource.group.should be_nil + @resource.group "opsdevs" + @resource.group.should == "opsdevs" + end + + it "also takes an integer for the group to run as" do + @resource.group 23 + @resource.group.should == 23 + end + + it "has a svn_username String attribute" do + @resource.svn_username "moartestsplz" + @resource.svn_username.should eql("moartestsplz") + end + + it "has a svn_password String attribute" do + @resource.svn_password "taftplz" + @resource.svn_password.should eql("taftplz") + end + + it "has a svn_arguments String attribute" do + @resource.svn_arguments "--more-taft plz" + @resource.svn_arguments.should eql("--more-taft plz") + end + + it "has a svn_info_args String attribute" do + @resource.svn_info_args.should be_nil + @resource.svn_info_args("--no-moar-plaintext-creds yep") + @resource.svn_info_args.should == "--no-moar-plaintext-creds yep" + end + + it "takes the depth as an integer for shallow clones" do + @resource.depth 5 + @resource.depth.should == 5 + lambda {@resource.depth "five"}.should raise_error(ArgumentError) + end + + it "defaults to nil depth for a full clone" do + @resource.depth.should be_nil + end + + it "takes a boolean for #enable_submodules" do + @resource.enable_submodules true + @resource.enable_submodules.should be_true + lambda {@resource.enable_submodules "lolz"}.should raise_error(ArgumentError) + end + + it "defaults to not enabling submodules" do + @resource.enable_submodules.should be_false + end + + it "takes a string for the remote" do + @resource.remote "opscode" + @resource.remote.should eql("opscode") + lambda {@resource.remote 1337}.should raise_error(ArgumentError) + end + + it "defaults to ``origin'' for the remote" do + @resource.remote.should == "origin" + end + + it "takes a string for the ssh wrapper" do + @resource.ssh_wrapper "with_ssh_fu" + @resource.ssh_wrapper.should eql("with_ssh_fu") + end + + it "defaults to nil for the ssh wrapper" do + @resource.ssh_wrapper.should be_nil + end + + describe "when it has repository, revision, user, and group" do + before do + @resource.destination("hell") + @resource.repository("apt") + @resource.revision("1.2.3") + @resource.user("root") + @resource.group("super_adventure_club") + end + + it "describes its state" do + state = @resource.state + state[:revision].should == "1.2.3" + end + + it "returns the destination as its identity" do + @resource.identity.should == "hell" + end + end + +end diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb new file mode 100644 index 0000000000..569602008b --- /dev/null +++ b/spec/unit/resource/script_spec.rb @@ -0,0 +1,69 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 + + it "should accept a string for the flags" do + @resource.flags "-f" + @resource.flags.should eql("-f") + end + + describe "when it has interpreter and flags" do + before do + @resource.command("grep") + @resource.interpreter("gcc") + @resource.flags("-al") + end + + it "returns the command as its identity" do + @resource.identity.should == "grep" + end + end + + +end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb new file mode 100644 index 0000000000..d7a90e8c7a --- /dev/null +++ b/spec/unit/resource/service_spec.rb @@ -0,0 +1,165 @@ +# +# Author:: AJ Christensen (<aj@hjksolutions.com>) +# Author:: Tyler Cloke (<tyler@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::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 + + it "should accept a string for the service reload command" do + @resource.reload_command "/etc/init.d/chef reload" + @resource.reload_command.should eql("/etc/init.d/chef reload") + end + + it "should not accept a regexp for the service reload command" do + lambda { + @resource.reload_command /.*/ + }.should raise_error(ArgumentError) + end + + %w{enabled running}.each do |attrib| + it "should accept true for #{attrib}" do + @resource.send(attrib, true) + @resource.send(attrib).should eql(true) + end + + it "should accept false for #{attrib}" do + @resource.send(attrib, false) + @resource.send(attrib).should eql(false) + end + + it "should not accept a string for #{attrib}" do + lambda { @resource.send(attrib, "poop") }.should raise_error(ArgumentError) + end + + it "should default all the feature support to false" do + support_hash = { :status => false, :restart => false, :reload=> false } + @resource.supports.should == support_hash + end + + it "should allow you to set what features this resource supports as a array" do + support_array = [ :status, :restart ] + support_hash = { :status => true, :restart => true, :reload => false } + @resource.supports(support_array) + @resource.supports.should == support_hash + end + + it "should allow you to set what features this resource supports as a hash" do + support_hash = { :status => true, :restart => true, :reload => false } + @resource.supports(support_hash) + @resource.supports.should == support_hash + end + end + + describe "when it has pattern and supports" do + before do + @resource.service_name("superfriend") + @resource.enabled(true) + @resource.running(false) + end + + it "describes its state" do + state = @resource.state + state[:enabled].should eql(true) + state[:running].should eql(false) + end + + it "returns the service name as its identity" do + @resource.identity.should == "superfriend" + end + end + + +end diff --git a/spec/unit/resource/smartos_package_spec.rb b/spec/unit/resource/smartos_package_spec.rb new file mode 100644 index 0000000000..ca815320ad --- /dev/null +++ b/spec/unit/resource/smartos_package_spec.rb @@ -0,0 +1,38 @@ +# +# Author:: Thomas Bishop (<bishop.thomas@gmail.com>) +# Copyright:: Copyright (c) 2010 Thomas Bishop +# 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::SmartOSPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::SmartOSPackage.new("foo") + end + + it "should return a Chef::Resource::SmartOSPackage" do + @resource.should be_a_kind_of(Chef::Resource::SmartOSPackage) + end + + it "should set the resource_name to :smartos_package" do + @resource.resource_name.should eql(:smartos_package) + end + + it "should set the provider to Chef::Provider::Package::SmartOS" do + @resource.provider.should eql(Chef::Provider::Package::SmartOS) + end +end diff --git a/spec/unit/resource/subversion_spec.rb b/spec/unit/resource/subversion_spec.rb new file mode 100644 index 0000000000..650eb010a6 --- /dev/null +++ b/spec/unit/resource/subversion_spec.rb @@ -0,0 +1,58 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Subversion do + + before do + @svn = Chef::Resource::Subversion.new("ohai, svn project!") + end + + it "is a subclass of Resource::Scm" do + @svn.should be_an_instance_of(Chef::Resource::Subversion) + @svn.should be_a_kind_of(Chef::Resource::Scm) + end + + it "uses the subversion provider" do + @svn.provider.should eql(Chef::Provider::Subversion) + end + + it "allows the force_export action" do + @svn.allowed_actions.should include(:force_export) + end + + it "sets svn info arguments to --no-auth-cache by default" do + @svn.svn_info_args.should == '--no-auth-cache' + end + + it "resets svn info arguments to nil when given false in the setter" do + @svn.svn_info_args(false) + @svn.svn_info_args.should be_nil + end + + it "sets svn arguments to --no-auth-cache by default" do + @svn.svn_arguments.should == '--no-auth-cache' + end + + it "resets svn arguments to nil when given false in the setter" do + @svn.svn_arguments(false) + @svn.svn_arguments.should be_nil + end + +end diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb new file mode 100644 index 0000000000..f3313611db --- /dev/null +++ b/spec/unit/resource/template_spec.rb @@ -0,0 +1,108 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Template do + + before(:each) do + @resource = Chef::Resource::Template.new("fakey_fakerton") + end + + describe "initialize" do + 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 + end + + describe "source" do + it "should accept a string for the template source" do + @resource.source "something" + @resource.source.should eql("something") + end + + it "should have a default based on the param name with .erb appended" do + @resource.source.should eql("fakey_fakerton.erb") + end + + it "should use only the basename of the file as the default" do + r = Chef::Resource::Template.new("/tmp/obit/fakey_fakerton") + r.source.should eql("fakey_fakerton.erb") + end + end + + describe "variables" do + it "should accept a hash for the variable list" do + @resource.variables({ :reluctance => :awkward }) + @resource.variables.should == { :reluctance => :awkward } + end + end + + describe "cookbook" do + it "should accept a string for the cookbook name" do + @resource.cookbook("foo") + @resource.cookbook.should == "foo" + end + + it "should default to nil" do + @resource.cookbook.should == nil + end + end + + describe "local" do + it "should accept a boolean for whether a template is local or remote" do + @resource.local(true) + @resource.local.should == true + end + + it "should default to false" do + @resource.local.should == false + end + end + + describe "when it has a path, owner, group, mode, and checksum" do + before do + @resource.path("/tmp/foo.txt") + @resource.owner("root") + @resource.group("wheel") + @resource.mode("0644") + @resource.checksum("1" * 64) + end + + context "on unix", :unix_only do + it "describes its state" do + state = @resource.state + state[:owner].should == "root" + state[:group].should == "wheel" + state[:mode].should == "0644" + state[:checksum].should == "1" * 64 + end + end + + context "on windows", :windows_only do + # according to Chef::Resource::File, windows state attributes are rights + deny_rights + pending "it describes its state" + end + + it "returns the file path as its identity" do + @resource.identity.should == "/tmp/foo.txt" + end + end +end diff --git a/spec/unit/resource/timestamped_deploy_spec.rb b/spec/unit/resource/timestamped_deploy_spec.rb new file mode 100644 index 0000000000..89b881830a --- /dev/null +++ b/spec/unit/resource/timestamped_deploy_spec.rb @@ -0,0 +1,28 @@ +# +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Copyright:: Copyright (c) 2009 Daniel DeLeo +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::TimestampedDeploy do + + it "defaults to the TimestampedDeploy provider" do + @resource = Chef::Resource::TimestampedDeploy.new("stuff") + @resource.provider.should == Chef::Provider::Deploy::Timestamped + end + +end diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb new file mode 100644 index 0000000000..3361921173 --- /dev/null +++ b/spec/unit/resource/user_spec.rb @@ -0,0 +1,122 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::User, "initialize" do + before(:each) do + @resource = Chef::Resource::User.new("adam") + end + + it "should create a new Chef::Resource::User" do + @resource.should be_a_kind_of(Chef::Resource) + @resource.should be_a_kind_of(Chef::Resource::User) + end + + it "should set the resource_name to :user" do + @resource.resource_name.should eql(:user) + end + + it "should set the username equal to the argument to initialize" do + @resource.username.should eql("adam") + end + + %w{comment uid gid home shell password}.each do |attrib| + it "should set #{attrib} to nil" do + @resource.send(attrib).should eql(nil) + end + end + + it "should set action to :create" do + @resource.action.should eql(:create) + end + + it "should set supports[:manage_home] to false" do + @resource.supports[:manage_home].should eql(false) + end + + it "should set supports[:non_unique] to false" do + @resource.supports[:non_unique].should eql(false) + end + + %w{create remove modify manage lock unlock}.each do |action| + it "should allow action #{action}" do + @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) + end + end +end + +%w{username comment home shell password}.each do |attrib| + describe Chef::Resource::User, attrib do + before(:each) do + @resource = Chef::Resource::User.new("adam") + end + + it "should allow a string" do + @resource.send(attrib, "adam") + @resource.send(attrib).should eql("adam") + end + + it "should not allow a hash" do + lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) + end + end +end + +%w{uid gid}.each do |attrib| + describe Chef::Resource::User, attrib do + before(:each) do + @resource = Chef::Resource::User.new("adam") + end + + it "should allow a string" do + @resource.send(attrib, "100") + @resource.send(attrib).should eql("100") + end + + it "should allow an integer" do + @resource.send(attrib, 100) + @resource.send(attrib).should eql(100) + end + + it "should not allow a hash" do + lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) + end + end + + describe "when it has uid, gid, and home" do + before do + @resource = Chef::Resource::User.new("root") + @resource.uid(123) + @resource.gid(456) + @resource.home("/usr/local/root/") + end + + it "describes its state" do + state = @resource.state + state[:uid].should == 123 + state[:gid].should == 456 + state[:home].should == "/usr/local/root/" + end + + it "returns the username as its identity" do + @resource.identity.should == "root" + end + end + +end diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb new file mode 100644 index 0000000000..a0f4aaee55 --- /dev/null +++ b/spec/unit/resource/yum_package_spec.rb @@ -0,0 +1,85 @@ +# +# Author:: AJ Christensen (<aj@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::YumPackage, "initialize" do + + before(:each) do + @resource = Chef::Resource::YumPackage.new("foo") + end + + it "should return a Chef::Resource::YumPackage" do + @resource.should be_a_kind_of(Chef::Resource::YumPackage) + end + + it "should set the resource_name to :yum_package" do + @resource.resource_name.should eql(:yum_package) + end + + it "should set the provider to Chef::Provider::Package::Yum" do + @resource.provider.should eql(Chef::Provider::Package::Yum) + end +end + +describe Chef::Resource::YumPackage, "arch" do + before(:each) do + @resource = Chef::Resource::YumPackage.new("foo") + end + + it "should set the arch variable to whatever is passed in" do + @resource.arch("i386") + @resource.arch.should eql("i386") + end +end + +describe Chef::Resource::YumPackage, "flush_cache" do + before(:each) do + @resource = Chef::Resource::YumPackage.new("foo") + end + + it "should default the flush timing to false" do + flush_hash = { :before => false, :after => false } + @resource.flush_cache.should == flush_hash + end + + it "should allow you to set the flush timing with an array" do + flush_array = [ :before, :after ] + flush_hash = { :before => true, :after => true } + @resource.flush_cache(flush_array) + @resource.flush_cache.should == flush_hash + end + + it "should allow you to set the flush timing with a hash" do + flush_hash = { :before => true, :after => true } + @resource.flush_cache(flush_hash) + @resource.flush_cache.should == flush_hash + end +end + +describe Chef::Resource::YumPackage, "allow_downgrade" do + before(:each) do + @resource = Chef::Resource::YumPackage.new("foo") + end + + it "should allow you to specify whether allow_downgrade is true or false" do + lambda { @resource.allow_downgrade true }.should_not raise_error(ArgumentError) + lambda { @resource.allow_downgrade false }.should_not raise_error(ArgumentError) + lambda { @resource.allow_downgrade "monkey" }.should raise_error(ArgumentError) + end +end |