diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-23 14:26:56 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-23 14:26:56 -0500 |
| commit | 048464f2563d3ccf781c16b873be6b74441f1f85 (patch) | |
| tree | 939a649265fbd20356205d12111f7f859f280d27 /spec/unit/other | |
| parent | 84146d00eed4765e6dbe05dd8de9f4c3625463b7 (diff) | |
| download | puppet-048464f2563d3ccf781c16b873be6b74441f1f85.tar.gz puppet-048464f2563d3ccf781c16b873be6b74441f1f85.tar.xz puppet-048464f2563d3ccf781c16b873be6b74441f1f85.zip | |
Adding my first integration test, verifying that
checksum interaction behaves as I expect when
interacting with the file terminus.
I've also changed how files and checksums behave a bit.
Files now create model instances with the content as
the only argument during initialization, and checksums
now calculate their checksums rather than having them passed
in.
Diffstat (limited to 'spec/unit/other')
| -rwxr-xr-x | spec/unit/other/checksum.rb | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/spec/unit/other/checksum.rb b/spec/unit/other/checksum.rb index 5610870a6..6a63e833d 100755 --- a/spec/unit/other/checksum.rb +++ b/spec/unit/other/checksum.rb @@ -9,35 +9,67 @@ require 'puppet/checksum' describe Puppet::Checksum do it "should have 'Checksum' and the checksum algorithm when converted to a string" do - sum = Puppet::Checksum.new("whatever") - sum.algorithm = "yay" - sum.to_s.should == "Checksum<{yay}whatever>" + inst = Puppet::Checksum.new("whatever", "md5") + inst.to_s.should == "Checksum<{md5}#{inst.checksum}>" end it "should convert algorithm names to symbols when they are set after checksum creation" do sum = Puppet::Checksum.new("whatever") - sum.algorithm = "yay" - sum.algorithm.should == :yay + sum.algorithm = "md5" + sum.algorithm.should == :md5 + end + + it "should return the checksum as the name" do + sum = Puppet::Checksum.new("whatever") + sum.checksum.should == sum.name end end describe Puppet::Checksum, " when initializing" do - it "should require a name" do + before do + @content = "this is some content" + @sum = Puppet::Checksum.new(@content) + end + + it "should require content" do proc { Puppet::Checksum.new(nil) }.should raise_error(ArgumentError) end - it "should set the name appropriately" do - Puppet::Checksum.new("whatever").name.should == "whatever" + it "should set the content appropriately" do + @sum.content.should == @content + end + + it "should calculate the checksum" do + require 'digest/md5' + Digest::MD5.expects(:hexdigest).with(@content).returns(:mychecksum) + @sum.checksum.should == :mychecksum + end + + it "should not calculate the checksum until it is asked for" do + require 'digest/md5' + Digest::MD5.expects(:hexdigest).never + sum = Puppet::Checksum.new(@content, :md5) end - it "should parse checksum algorithms out of the name if they are there" do - sum = Puppet::Checksum.new("{other}whatever") - sum.algorithm.should == :other - sum.name.should == "whatever" + it "should remove the old checksum value if the algorithm is changed" do + Digest::MD5.expects(:hexdigest).with(@content).returns(:oldsum) + oldsum = @sum.checksum + @sum.algorithm = :sha1 + Digest::SHA1.expects(:hexdigest).with(@content).returns(:newsum) + @sum.checksum.should == :newsum end it "should default to 'md5' as the checksum algorithm if the algorithm is not in the name" do - Puppet::Checksum.new("whatever").algorithm.should == :md5 + @sum.algorithm.should == :md5 + end + + it "should support specifying the algorithm during initialization" do + sum = Puppet::Checksum.new(@content, :sha1) + sum.algorithm.should == :sha1 + end + + it "should fail when an unsupported algorithm is used" do + proc { Puppet::Checksum.new(@content, :nope) }.should raise_error(ArgumentError) end end |
