diff options
author | Tim Smith <tsmith@chef.io> | 2019-09-10 09:31:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-10 09:31:44 -0700 |
commit | 906d6a94026119ed56580f8ac967c982aed9efdb (patch) | |
tree | 3a28e1b86299e31f3a523a5f3101b3ec414f104d /spec | |
parent | 4013d9314812e131226a32d352bbfe014d2c49ad (diff) | |
parent | 7aae7e760676d829f1dd6a45438bbc19518fc619 (diff) | |
download | chef-906d6a94026119ed56580f8ac967c982aed9efdb.tar.gz |
Merge pull request #8869 from MsysTechnologiesllc/Kapil/MSYS-1094_user_resource_does_not_handle_a_gid_specified_as_a_string
Fix for user resource does not handle a gid specified as a string
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/user_spec.rb | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index ddfe9e6c86..ce04ec8fd2 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -444,35 +444,51 @@ describe Chef::Provider::User do describe "convert_group_name" do before do - @new_resource.gid("999") @group = EtcGrnamIsh.new("wheel", "*", 999, []) end - it "should lookup the group name locally" do - expect(Etc).to receive(:getgrnam).with("999").and_return(@group) - expect(@provider.convert_group_name).to eq(999) - end + context "when user passes group name in gid" do + before do + @new_resource.gid("wheel") + end - it "should raise an error if we can't translate the group name during resource assertions" do - expect(Etc).to receive(:getgrnam).and_raise(ArgumentError) - @provider.action = :create - @provider.define_resource_requirements - @provider.convert_group_name - expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::User) - end + it "should lookup the group name locally" do + expect(Etc).to receive(:getgrnam).with("wheel").and_return(@group) + expect(@provider.convert_group_name).to eq(999) + end + + it "should raise an error if we can't translate the group name during resource assertions" do + expect(Etc).to receive(:getgrnam).and_raise(ArgumentError) + @provider.action = :create + @provider.define_resource_requirements + @provider.convert_group_name + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::User) + end - it "does not raise an error if we can't translate the group name during resource assertions if we are removing the user" do - expect(Etc).to receive(:getgrnam).and_raise(ArgumentError) - @provider.action = :remove - @provider.define_resource_requirements - @provider.convert_group_name - expect { @provider.process_resource_requirements }.not_to raise_error + it "does not raise an error if we can't translate the group name during resource assertions if we are removing the user" do + expect(Etc).to receive(:getgrnam).and_raise(ArgumentError) + @provider.action = :remove + @provider.define_resource_requirements + @provider.convert_group_name + expect { @provider.process_resource_requirements }.not_to raise_error + end + + it "should set the new resources gid to the integerized version if available" do + expect(Etc).to receive(:getgrnam).with("wheel").and_return(@group) + @provider.convert_group_name + expect(@new_resource.gid).to eq(999) + end end - it "should set the new resources gid to the integerized version if available" do - expect(Etc).to receive(:getgrnam).with("999").and_return(@group) - @provider.convert_group_name - expect(@new_resource.gid).to eq(999) + context "when user passes group id in gid" do + before do + @new_resource.gid(999) + end + + it "should not call getgrnam" do + expect(Etc).not_to receive(:getgrnam) + @provider.convert_group_name + end end end end |