summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2012-11-16 09:50:50 -0800
committerBryan McLellan <btm@opscode.com>2013-11-06 09:13:46 -0800
commit78356de11f928bd673ac9e76328092ab74049c9d (patch)
treeb995d19b68532c7dfe156cac61f52acf3ebd27e6 /spec/support
parentce4cb2562af999347e26fa290d2d1ddf8deafd92 (diff)
downloadchef-78356de11f928bd673ac9e76328092ab74049c9d.tar.gz
CHEF-3582: Fix #check_lock under why-run
We assume in whyrun mode that a non-existant user would be created before we attempt to lock it, so we return false from #check_lock when user does not exist and we are in why_run mode. Conflicts: chef/lib/chef/provider/user/useradd.rb
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared/unit/provider/useradd_based_user_provider.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
index 3b8f8678bf..e9fe06dfd7 100644
--- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb
+++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
@@ -335,6 +335,24 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
lambda { provider.check_lock }.should raise_error(Mixlib::ShellOut::ShellCommandFailed)
end
end
+
+ context "when in why run mode" do
+ before do
+ passwd_status = mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n")
+ provider.should_receive(:shell_out!).
+ with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}).
+ and_return(passwd_status)
+ Chef::Config[:why_run] = true
+ end
+
+ it "should return false if the user does not exist" do
+ provider.check_lock.should eql(false)
+ end
+
+ it "should not raise an error if the user does not exist" do
+ lambda { provider.check_lock }.should_not raise_error
+ end
+ end
end
describe "when locking the user" do