summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-08 12:14:11 -0500
committerLuke Kanies <luke@madstop.com>2008-10-08 12:14:11 -0500
commit2153baed8c6b99f9b77ed2f63fb24433bd72058c (patch)
tree45674f79f86cef7f389c8af72b99250c0cb7fc8e
parent80e5c111fd2d227ef076fd0409213f30af13bc56 (diff)
downloadpuppet-2153baed8c6b99f9b77ed2f63fb24433bd72058c.tar.gz
puppet-2153baed8c6b99f9b77ed2f63fb24433bd72058c.tar.xz
puppet-2153baed8c6b99f9b77ed2f63fb24433bd72058c.zip
Fixing #1640 - file groups now no longer get set on every run
(this was a regression caused by other work I did). Signed-off-by: Luke Kanies <luke@madstop.com>
-rwxr-xr-xlib/puppet/type/file/group.rb15
-rwxr-xr-xspec/unit/type/file/group.rb33
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}