Skip to content

Commit 94505da

Browse files
committed
Merge branch 'chef-96' of git://github.com/fujin/chef into integration
2 parents bbc71e1 + 198a3ae commit 94505da

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

chef/lib/chef/provider/group/groupadd.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ def remove_group
5454
end
5555

5656
def modify_group_members
57-
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
58-
run_command(:command => "gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
57+
unless @new_resource.members.empty?
58+
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
59+
run_command(:command => "gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
60+
else
61+
Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members")
62+
end
5963
end
6064

6165
# Little bit of magic as per Adam's useradd provider to pull the assign the command line flags

chef/spec/unit/provider/group/groupadd_spec.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,38 @@
129129
@new_resource = mock("Chef::Resource::Group",
130130
:null_object => true,
131131
:group_name => "aj",
132-
:members => [ "all", "your", "base", "are", "belong", "to", "us" ]
132+
:members => [ "all", "your", "base" ]
133133
)
134134
@new_resource.stub!(:to_s).and_return("group[aj]")
135135
@provider = Chef::Provider::Group::Groupadd.new(@node, @new_resource)
136136
@provider.stub!(:run_command).and_return(true)
137137
end
138138

139-
it "should log an appropriate debug message" do
140-
Chef::Log.should_receive(:debug).with("group[aj]: setting group members to all, your, base, are, belong, to, us")
141-
@provider.modify_group_members
139+
describe "with an empty members array" do
140+
before do
141+
@new_resource.stub!(:members).and_return([])
142+
end
143+
144+
it "should log an appropriate message" do
145+
Chef::Log.should_receive(:debug).with("group[aj]: not changing group members, the group has no members")
146+
@provider.modify_group_members
147+
end
142148
end
143149

144-
it "should run gpasswd with the members joined by ',' and the target group" do
145-
@provider.should_receive(:run_command).with({:command => "gpasswd -M all,your,base,are,belong,to,us aj"})
146-
@provider.modify_group_members
150+
describe "with supplied members" do
151+
before do
152+
@new_resource.stub!(:members).and_return(["all", "your", "base"])
153+
end
154+
155+
it "should log an appropriate debug message" do
156+
Chef::Log.should_receive(:debug).with("group[aj]: setting group members to all, your, base")
157+
@provider.modify_group_members
158+
end
159+
160+
it "should run gpasswd with the members joined by ',' followed by the target group" do
161+
@provider.should_receive(:run_command).with({:command => "gpasswd -M all,your,base aj"})
162+
@provider.modify_group_members
163+
end
147164
end
148165
end
149166

0 commit comments

Comments
 (0)