diff options
-rwxr-xr-x | lib/puppet/type/file/checksum.rb | 2 | ||||
-rwxr-xr-x | spec/unit/type/file.rb | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index 27edee13d..785ed0fee 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -53,7 +53,7 @@ Puppet::Type.type(:file).newproperty(:checksum) do else if FileTest.directory?(@resource[:path]) return :time - elsif @resource[:source] + elsif @resource[:source] and value.to_s != "md5" self.warning("Files with source set must use md5 as checksum. Forcing to md5 from %s for %s" % [ value, @resource[:path] ]) return :md5 else diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 552d284a7..0b7bfa8fb 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -41,14 +41,38 @@ describe Puppet::Type.type(:file) do lambda { @file.retrieve }.should raise_error(Puppet::Error) end - it "should always have a checksum type of md5" do + it "should have a checksum type of md5 and warn if retrieving with mtime" do File.open(@path, "w") do |f| f.puts "foo" end + @file.property(:checksum).expects(:warning).with("Files with source set must use md5 as checksum. Forcing to md5 from %s for %s" % [:mtime, @path]) @file[:checksum] = :mtime @file.property(:checksum).checktype.should == :md5 @file.property(:checksum).retrieve.should == "{md5}d3b07384d113edec49eaa6238ad5ff00" + end + + it "should have a checksum type of md5 and warn if retrieving with md5lite" do + File.open(@path, "w") do |f| f.puts "foo" end + @file.property(:checksum).expects(:warning).with("Files with source set must use md5 as checksum. Forcing to md5 from %s for %s" % [:md5lite, @path]) + @file[:checksum] = :md5lite + @file.property(:checksum).checktype.should == :md5 + @file.property(:checksum).retrieve.should == "{md5}d3b07384d113edec49eaa6238ad5ff00" + end + + + it "should have a checksum type of md5 if getsum called with mtime" do + File.open(@path, "w") do |f| f.puts "foo" end + @file[:checksum] = :md5 + @file.property(:checksum).checktype.should == :md5 @file.property(:checksum).getsum(:mtime).should == "{md5}d3b07384d113edec49eaa6238ad5ff00" end + it "should not warn if sumtype set to md5" do + File.open(@path, "w") do |f| f.puts "foo" end + @file.property(:checksum).expects(:warning).never + @file[:checksum] = :md5 + @file.property(:checksum).checktype.should == :md5 + @file.property(:checksum).retrieve.should == "{md5}d3b07384d113edec49eaa6238ad5ff00" + end + end describe "when retrieving remote files" do |