diff options
author | Kapil chouhan <kapil.chouhan@msystechnologies.com> | 2019-09-10 17:17:04 +0530 |
---|---|---|
committer | Kapil chouhan <kapil.chouhan@msystechnologies.com> | 2019-09-10 17:17:04 +0530 |
commit | 7aae7e760676d829f1dd6a45438bbc19518fc619 (patch) | |
tree | 844fffee2b1078cc7758313d6b4ef46ca0397e92 /spec | |
parent | a5854d7ae6100a4f4a125d15dbef8fa69ca1cfad (diff) | |
download | chef-7aae7e760676d829f1dd6a45438bbc19518fc619.tar.gz |
Fix for MSYS-1094 user resource does not handle a gid specified as a string
Signed-off-by: Kapil chouhan <kapil.chouhan@msystechnologies.com>
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 |