diff options
author | skippy <jonathan.yates.jones@gmail.com> | 2019-11-17 07:53:28 +0000 |
---|---|---|
committer | skippy <jonathan.yates.jones@gmail.com> | 2019-11-17 07:53:28 +0000 |
commit | 611611b50dfeea77d4de92f3746ed0b681209286 (patch) | |
tree | 77c3188a934316f787b2588f6b80d72db1a29f68 | |
parent | 8d69df6f0bbfc08a17bdd7af5f17aff345203274 (diff) | |
download | chef-611611b50dfeea77d4de92f3746ed0b681209286.tar.gz |
Resolved failing tests, fixed inverted logic
Signed-off-by: Jonathan Jones <gitmaster@thespooky.house>
-rw-r--r-- | lib/chef/provider/user/linux.rb | 8 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/useradd_based_user_provider.rb | 33 |
2 files changed, 25 insertions, 16 deletions
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb index 7e10957717..d905e1985f 100644 --- a/lib/chef/provider/user/linux.rb +++ b/lib/chef/provider/user/linux.rb @@ -28,7 +28,7 @@ class Chef end def manage_user - shell_out!("usermod", universal_options, usermod_options, new_resource.username, returns: return_codes) + shell_out!("usermod", universal_options, usermod_options, new_resource.username, returns: return_codes) end def remove_user @@ -60,13 +60,13 @@ class Chef ret_codes = [0] if updating_home? if new_resource.manage_home - home_dir_exist = shell_out!("test", "-d", new_resource.home, returns: [1]) - if home_dir_exist.error? + home_dir_not_exist = shell_out("test", "-d", new_resource.home, returns: [1]) + if home_dir_not_exist ret_codes << 12 end end end - ret_codes.to_s + ret_codes end def usermod_options 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 997d7350be..dc260460cd 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -159,7 +159,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option "-u", "1000", "-d", "/Users/mud", "-m", - "adam", {:returns=>[0,12]}]) + "adam"]) + command.concat([{:returns=>[0,12]}]) expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true) provider.create_user end @@ -180,7 +181,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option command.concat([ "-s", "/usr/bin/zsh", "-u", "1000", "-r", "-m", - "adam", {:returns=>[0]} ]) + "adam"]) + command.concat([{:returns=>[0]}]) expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true) provider.create_user end @@ -190,7 +192,11 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end describe "when managing a user" do - before(:each) do + let(:passwd_s_status) do + double("Mixlib::ShellOut command", exitstatus: 0, stdout: @stdout, stderr: @stderr, error!: nil) + end + + before(:each) do provider.new_resource.manage_home true provider.new_resource.home "/Users/mud" provider.new_resource.gid "23" @@ -203,7 +209,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option "-g", "23", "-d", "/Users/mud", "-m", - "adam", {:returns=>[0,12]}] + "adam"] + command.concat([{:returns=>[0,12]}]) expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true) provider.manage_user end @@ -214,7 +221,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option "-g", "23", "-d", "/Users/mud", "-m", - "adam", {:returns=>[0]}] + "adam"] + command.concat([{:returns=>[0,12]}]) expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true) provider.manage_user end @@ -223,7 +231,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option expect(provider).to receive(:updating_home?).at_least(:once).and_return(false) command = ["usermod", "-g", "23", - "adam", {:returns=>[0]} ] + "adam"] + command.concat([{:returns=>[0]}]) expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true) provider.manage_user end @@ -232,24 +241,24 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when removing a user" do it "should run userdel with the new resources user name" do - expect(provider).to receive(:shell_out_compacted!).with("userdel", @new_resource.username).and_return(true) + expect(provider).to receive(:shell_out_compacted!).with("userdel", @new_resource.username, {:returns=>[0]}).and_return(true) provider.remove_user end it "should run userdel with the new resources user name and -r if manage_home is true" do @new_resource.manage_home true - expect(provider).to receive(:shell_out_compacted!).with("userdel", "-r", @new_resource.username).and_return(true) + expect(provider).to receive(:shell_out_compacted!).with("userdel", "-r", @new_resource.username, {:returns=>[0]}).and_return(true) provider.remove_user end it "should run userdel with the new resources user name if non_unique is true" do - expect(provider).to receive(:shell_out_compacted!).with("userdel", @new_resource.username).and_return(true) + expect(provider).to receive(:shell_out_compacted!).with("userdel", @new_resource.username, {:returns=>[0]}).and_return(true) provider.remove_user end it "should run userdel with the new resources user name and -f if force is true" do @new_resource.force(true) - expect(provider).to receive(:shell_out_compacted!).with("userdel", "-f", @new_resource.username).and_return(true) + expect(provider).to receive(:shell_out_compacted!).with("userdel", "-f", @new_resource.username, {:returns=>[0]}).and_return(true) provider.remove_user end end @@ -335,14 +344,14 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when locking the user" do it "should run usermod -L with the new resources username" do - expect(provider).to receive(:shell_out_compacted!).with("usermod", "-L", @new_resource.username) + expect(provider).to receive(:shell_out_compacted!).with("usermod", "-L", @new_resource.username, {:returns=>[0]}) provider.lock_user end end describe "when unlocking the user" do it "should run usermod -L with the new resources username" do - expect(provider).to receive(:shell_out_compacted!).with("usermod", "-U", @new_resource.username) + expect(provider).to receive(:shell_out_compacted!).with("usermod", "-U", @new_resource.username, {:returns=>[0]}) provider.unlock_user end end |