summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-18 09:38:32 -0600
committerLuke Kanies <luke@madstop.com>2008-02-18 09:38:32 -0600
commita53106cf08c28e996502cba703f64944250a4b29 (patch)
tree4dee55340a4d91083e940fecb9087ecfaa7c279f /spec/unit
parentbe58bb5c4bc19e59685e0a8953eaf2d3b7844110 (diff)
parent62d7616a457f33eb660454fcdcefe8dab84522c0 (diff)
downloadpuppet-a53106cf08c28e996502cba703f64944250a4b29.tar.gz
puppet-a53106cf08c28e996502cba703f64944250a4b29.tar.xz
puppet-a53106cf08c28e996502cba703f64944250a4b29.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG man/man8/puppet.8
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/ral/types/file.rb2
-rwxr-xr-xspec/unit/simple_graph.rb11
-rwxr-xr-xspec/unit/util/checksums.rb99
3 files changed, 111 insertions, 1 deletions
diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb
index 1e20b06f4..7202e23e5 100755
--- a/spec/unit/ral/types/file.rb
+++ b/spec/unit/ral/types/file.rb
@@ -2,7 +2,7 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'puppet/type/pfile'
+require 'puppet/type/file'
describe Puppet::Type::File, " when used with replace=>false and content" do
before do
diff --git a/spec/unit/simple_graph.rb b/spec/unit/simple_graph.rb
index c8fe14cf3..e1e42e40f 100755
--- a/spec/unit/simple_graph.rb
+++ b/spec/unit/simple_graph.rb
@@ -266,4 +266,15 @@ describe Puppet::SimpleGraph, " when sorting the graph" do
add_edges :a => :b, :b => :e, :c => :a, :d => :c
proc { @graph.topsort }.should_not raise_error
end
+
+ # Our graph's add_edge method is smart enough not to add
+ # duplicate edges, so we use the objects, which it doesn't
+ # check.
+ it "should be able to sort graphs with duplicate edges" do
+ one = Puppet::Relationship.new(:a, :b)
+ @graph.add_edge(one)
+ two = Puppet::Relationship.new(:a, :b)
+ @graph.add_edge(two)
+ proc { @graph.topsort }.should_not raise_error
+ end
end
diff --git a/spec/unit/util/checksums.rb b/spec/unit/util/checksums.rb
new file mode 100755
index 000000000..31cf24f5b
--- /dev/null
+++ b/spec/unit/util/checksums.rb
@@ -0,0 +1,99 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-9-22.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/util/checksums'
+
+describe Puppet::Util::Checksums do
+ before do
+ @summer = Object.new
+ @summer.extend(Puppet::Util::Checksums)
+ end
+
+ content_sums = [:md5, :md5lite, :sha1, :sha1lite]
+ file_only = [:timestamp, :mtime]
+
+ content_sums.each do |sumtype|
+ it "should be able to calculate %s sums from strings" % sumtype do
+ @summer.should be_respond_to(sumtype)
+ end
+ end
+
+ [content_sums, file_only].flatten.each do |sumtype|
+ it "should be able to calculate %s sums from files" % sumtype do
+ @summer.should be_respond_to(sumtype.to_s + "_file")
+ end
+ end
+
+ {:md5 => Digest::MD5, :sha1 => Digest::SHA1}.each do |sum, klass|
+ describe("when using %s" % sum) do
+ it "should use #{klass} to calculate string checksums" do
+ klass.expects(:hexdigest).with("mycontent").returns "whatever"
+ @summer.send(sum, "mycontent").should == "whatever"
+ end
+
+ it "should use incremental #{klass} sums to calculate file checksums" do
+ digest = mock 'digest'
+ klass.expects(:new).returns digest
+
+ file = "/path/to/my/file"
+
+ fh = mock 'filehandle'
+ fh.expects(:read).with(512).times(3).returns("firstline").then.returns("secondline").then.returns(nil)
+ #fh.expects(:read).with(512).returns("secondline")
+ #fh.expects(:read).with(512).returns(nil)
+
+ File.expects(:open).with(file, "r").yields(fh)
+
+ digest.expects(:<<).with "firstline"
+ digest.expects(:<<).with "secondline"
+ digest.expects(:hexdigest).returns :mydigest
+
+ @summer.send(sum.to_s + "_file", file).should == :mydigest
+ end
+ end
+ end
+
+ {:md5lite => Digest::MD5, :sha1lite => Digest::SHA1}.each do |sum, klass|
+ describe("when using %s" % sum) do
+ it "should use #{klass} to calculate string checksums from the first 512 characters of the string" do
+ content = "this is a test" * 100
+ klass.expects(:hexdigest).with(content[0..511]).returns "whatever"
+ @summer.send(sum, content).should == "whatever"
+ end
+
+ it "should use #{klass} to calculate a sum from the first 512 characters in the file" do
+ digest = mock 'digest'
+ klass.expects(:new).returns digest
+
+ file = "/path/to/my/file"
+
+ fh = mock 'filehandle'
+ fh.expects(:read).with(512).returns('my content')
+
+ File.expects(:open).with(file, "r").yields(fh)
+
+ digest.expects(:<<).with "my content"
+ digest.expects(:hexdigest).returns :mydigest
+
+ @summer.send(sum.to_s + "_file", file).should == :mydigest
+ end
+ end
+ end
+
+ {:timestamp => :ctime, :mtime => :mtime}.each do |sum, method|
+ describe("when using %s" % sum) do
+ it "should use the '#{method}' on the file to determine the timestamp" do
+ file = "/my/file"
+ stat = mock 'stat', method => "mysum"
+
+ File.expects(:stat).with(file).returns(stat)
+
+ @summer.send(sum.to_s + "_file", file).should == "mysum"
+ end
+ end
+ end
+end