summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2010-03-13 14:57:39 +0100
committerJames Turnbull <james@lovedthanlost.net>2010-03-25 11:54:08 +1100
commit19863c07f983ec181fb81c797ee8b9c8d335e18c (patch)
tree6f457f4e7ff5eb2b7a0aebf3baf61664ab147dd2 /spec
parentfd76142b314c390205570d02383607ff91b23391 (diff)
Fix #2929 - Allow checksum to be "none"
File checksum is "md5" by default. When managing local files (not sourced or content) it might be desirable to not checksum files, especially when managing deep hierarchies containing many files. This patch allows to write such manifests: file { "/path/to/deep/hierarchy": owner => brice, recurse => true, checksum => none } Then puppet(d) won't checksum those files, just manage their ownership. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/file_serving/fileset.rb6
-rwxr-xr-xspec/unit/file_serving/terminus_helper.rb10
-rwxr-xr-xspec/unit/type/file.rb7
-rw-r--r--spec/unit/type/file/checksum.rb28
-rwxr-xr-xspec/unit/util/checksums.rb8
5 files changed, 58 insertions, 1 deletions
diff --git a/spec/unit/file_serving/fileset.rb b/spec/unit/file_serving/fileset.rb
index 55cc2a911..c03522d0e 100755
--- a/spec/unit/file_serving/fileset.rb
+++ b/spec/unit/file_serving/fileset.rb
@@ -42,6 +42,12 @@ describe Puppet::FileServing::Fileset, " when initializing" do
set.links.should == :manage
end
+ it "should accept a 'checksum_type' option" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ set = Puppet::FileServing::Fileset.new("/some/file", :checksum_type => :test)
+ set.checksum_type.should == :test
+ end
+
it "should fail if 'links' is set to anything other than :manage or :follow" do
proc { Puppet::FileServing::Fileset.new("/some/file", :links => :whatever) }.should raise_error(ArgumentError)
end
diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb
index d0c06f126..98c64b712 100755
--- a/spec/unit/file_serving/terminus_helper.rb
+++ b/spec/unit/file_serving/terminus_helper.rb
@@ -76,6 +76,16 @@ describe Puppet::FileServing::TerminusHelper do
@helper.path2instances(@request, "/my/file")
end
+ it "should set the request checksum_type if one is provided" do
+ @one.expects(:checksum_type=).with :test
+ @two.expects(:checksum_type=).with :test
+ @model.expects(:new).returns(@one)
+ @model.expects(:new).returns(@two)
+
+ @request.options[:checksum_type] = :test
+ @helper.path2instances(@request, "/my/file")
+ end
+
it "should collect the instance's attributes" do
@one.expects(:collect)
@two.expects(:collect)
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index 1b3fe6a60..b5963a666 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -320,6 +320,13 @@ describe Puppet::Type.type(:file) do
@file.expects(:newchild).with("my/file").returns "fiebar"
@file.recurse_local.should == {"my/file" => "fiebar"}
end
+
+ it "should set checksum_type to none if this file checksum is none" do
+ @file[:checksum] = :none
+ Puppet::FileServing::Metadata.expects(:search).with { |path,params| params[:checksum_type] == :none }.returns [@metadata]
+ @file.expects(:newchild).with("my/file").returns "fiebar"
+ @file.recurse_local
+ end
end
it "should have a method for performing link recursion" do
diff --git a/spec/unit/type/file/checksum.rb b/spec/unit/type/file/checksum.rb
new file mode 100644
index 000000000..5d715d15c
--- /dev/null
+++ b/spec/unit/type/file/checksum.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+checksum = Puppet::Type.type(:file).attrclass(:checksum)
+describe checksum do
+ before do
+ # Wow that's a messy interface to the resource.
+ @resource = stub 'resource', :[] => nil, :[]= => nil, :property => nil, :newattr => nil, :parameter => nil
+ end
+
+ it "should be a subclass of Property" do
+ checksum.superclass.must == Puppet::Property
+ end
+
+ it "should have default checksum of :md5" do
+ @checksum = checksum.new(:resource => @resource)
+ @checksum.checktype.should == :md5
+ end
+
+ [:none, nil, ""].each do |ck|
+ it "should use a none checksum for #{ck.inspect}" do
+ @checksum = checksum.new(:resource => @resource)
+ @checksum.should = "none"
+ @checksum.checktype.should == :none
+ end
+ end
+end
diff --git a/spec/unit/util/checksums.rb b/spec/unit/util/checksums.rb
index d31d7a000..615ed902c 100755
--- a/spec/unit/util/checksums.rb
+++ b/spec/unit/util/checksums.rb
@@ -14,7 +14,7 @@ describe Puppet::Util::Checksums do
end
content_sums = [:md5, :md5lite, :sha1, :sha1lite]
- file_only = [:ctime, :mtime]
+ file_only = [:ctime, :mtime, :none]
content_sums.each do |sumtype|
it "should be able to calculate %s sums from strings" % sumtype do
@@ -104,4 +104,10 @@ describe Puppet::Util::Checksums do
end
end
end
+
+ describe "when using the none checksum" do
+ it "should return an empty string" do
+ @summer.none_file("/my/file").should == ""
+ end
+ end
end