diff options
-rwxr-xr-x | lib/puppet/type/file/group.rb | 15 | ||||
-rwxr-xr-x | spec/unit/type/file/group.rb | 33 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lib/puppet/type/file/group.rb b/lib/puppet/type/file/group.rb index 75beb537a..56883add6 100755 --- a/lib/puppet/type/file/group.rb +++ b/lib/puppet/type/file/group.rb @@ -46,6 +46,21 @@ module Puppet end end + def insync?(current) + @should.each do |value| + if value =~ /^\d+$/ + gid = Integer(value) + elsif value.is_a?(String) + fail "Could not find group %s" % value unless gid = gid(value) + else + gid = value + end + + return true if gid == current + end + return false + end + def retrieve return :absent unless stat = resource.stat(false) diff --git a/spec/unit/type/file/group.rb b/spec/unit/type/file/group.rb index 2b47c75dd..856b05b0d 100755 --- a/spec/unit/type/file/group.rb +++ b/spec/unit/type/file/group.rb @@ -6,7 +6,7 @@ property = Puppet::Type.type(:file).attrclass(:group) describe property do before do - @resource = mock 'resource' + @resource = stub 'resource', :line => "foo", :file => "bar" @resource.stubs(:[]).returns "foo" @resource.stubs(:[]).with(:path).returns "/my/file" @group = property.new :resource => @resource @@ -53,6 +53,37 @@ describe property do end end + describe "when determining if the file is in sync" do + it "should directly compare the group values if the desired group is an integer" do + @group.should = [10] + @group.must be_insync(10) + end + + it "should treat numeric strings as integers" do + @group.should = ["10"] + @group.must be_insync(10) + end + + it "should convert the group name to an integer if the desired group is a string" do + @group.expects(:gid).with("foo").returns 10 + @group.should = %w{foo} + + @group.must be_insync(10) + end + + it "should fail if it cannot convert a group name to an integer" do + @group.expects(:gid).with("foo").returns nil + @group.should = %w{foo} + + lambda { @group.insync?(10) }.should raise_error(Puppet::Error) + end + + it "should return false if the groups are not equal" do + @group.should = [10] + @group.should_not be_insync(20) + end + end + describe "when changing the group" do before do @group.should = %w{one} |