diff options
author | Luke Kanies <luke@madstop.com> | 2005-07-11 20:51:52 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-07-11 20:51:52 +0000 |
commit | 75e27cf8f387816526860df3ad0d38ddce8eeb01 (patch) | |
tree | a9a251e7e28a6573ad654eb7ef94fe29e42fb97a | |
parent | 0417fb59f4493b98fea9b03a60cb21ffc0f8bed4 (diff) | |
download | puppet-75e27cf8f387816526860df3ad0d38ddce8eeb01.tar.gz puppet-75e27cf8f387816526860df3ad0d38ddce8eeb01.tar.xz puppet-75e27cf8f387816526860df3ad0d38ddce8eeb01.zip |
cleaning up bugs in the tests, and adding more error checking around the bugs
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@359 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/storage.rb | 8 | ||||
-rw-r--r-- | lib/puppet/type/pfile.rb | 15 | ||||
-rw-r--r-- | test/types/tc_file.rb | 37 |
3 files changed, 48 insertions, 12 deletions
diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb index 67969c76f..eb639e32e 100644 --- a/lib/puppet/storage.rb +++ b/lib/puppet/storage.rb @@ -38,7 +38,13 @@ module Puppet file.each { |line| myclass, key, value = line.split(@@splitchar) - @@state[eval(myclass)][key] = Marshal::load(value) + begin + @@state[eval(myclass)][key] = Marshal::load(value) + rescue => detail + raise RuntimeError, "Failed to load value for %s::%s => %s" % [ + myclass,key,detail + ], caller + end } } diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 6b4ecbc5d..94ef94736 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -55,15 +55,15 @@ module Puppet if hash = state[self.parent[:path]] if hash.include?(@checktype) @should = hash[@checktype] - Puppet.warning "Found checksum %s for %s" % + Puppet.debug "Found checksum %s for %s" % [@should,self.parent[:path]] else - Puppet.warning "Found checksum for %s but not of type %s" % + Puppet.debug "Found checksum for %s but not of type %s" % [self.parent[:path],@checktype] @should = nil end else - Puppet.warning "No checksum for %s" % self.parent[:path] + Puppet.debug "No checksum for %s" % self.parent[:path] end end @@ -121,13 +121,19 @@ module Puppet Puppet.err "@is is nil" end if self.updatesum + # set the @should value to the new @is value + # most important for testing + @should = @is return :file_modified else + # set the @should value, because it starts out as nil + @should = @is return nil end end def updatesum + result = false state = Puppet::Storage.state(self) unless state.include?(self.parent[:path]) Puppet.debug "Initializing state hash for %s" % @@ -137,6 +143,9 @@ module Puppet end # if we're replacing, vs. updating if state[self.parent[:path]].include?(@checktype) + unless defined? @should + raise "@should is not initialized for %s, even though we found a checksum" % self.parent[:path] + end Puppet.debug "Replacing checksum %s with %s" % [state[self.parent[:path]][@checktype],@is] Puppet.debug "@is: %s; @should: %s" % [@is,@should] diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 0b50d94f2..fb95bfbb6 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -26,7 +26,7 @@ class TestFile < Test::Unit::TestCase end def teardown - Puppet::Type::PFile.clear + Puppet::Type.allclear system("rm -f %s" % Puppet[:statefile]) end @@ -126,11 +126,18 @@ class TestFile < Test::Unit::TestCase } end - def test_checksums + def test_xchecksums types = %w{md5 md5lite timestamp ctime} files = %w{/tmp/sumtest} + assert_nothing_raised() { + Puppet::Storage.init + # Puppet::Storage.load + } types.each { |type| files.each { |path| + if Puppet[:debug] + Puppet.info "Testing %s on %s" % [type,path] + end file = nil events = nil assert_nothing_raised() { @@ -166,6 +173,14 @@ class TestFile < Test::Unit::TestCase } #system("cat %s" % path) } + Puppet::Type::PFile.clear + # now recreate the file + assert_nothing_raised() { + file = Puppet::Type::PFile.new( + :path => path, + :checksum => type + ) + } assert_nothing_raised() { file.evaluate } @@ -184,11 +199,15 @@ class TestFile < Test::Unit::TestCase } } } + # clean up so i don't screw up other tests + Puppet::Storage.clear end def cyclefile(path) file = nil changes = nil + comp = nil + trans = nil assert_nothing_raised { file = Puppet::Type::PFile.new( :path => path, @@ -196,15 +215,20 @@ class TestFile < Test::Unit::TestCase :checksum => "md5" ) } + comp = Puppet::Component.new( + :name => "component" + ) + comp.push file assert_nothing_raised { - changes = file.evaluate + trans = comp.evaluate } - changes.each { |change| - change.go + assert_nothing_raised { + trans.evaluate } #assert_nothing_raised { # file.sync #} + Puppet::Type.allclear end def test_recursion @@ -212,17 +236,14 @@ class TestFile < Test::Unit::TestCase tmpfile = File.join(path,"testing") system("mkdir -p #{path}") cyclefile(path) - Puppet::Type::PFile.clear File.open(tmpfile, File::WRONLY|File::CREAT|File::APPEND) { |of| of.puts "yayness" } cyclefile(path) - Puppet::Type::PFile.clear File.open(tmpfile, File::WRONLY|File::APPEND) { |of| of.puts "goodness" } cyclefile(path) - Puppet::Type::PFile.clear system("rm -rf #{path}") end end |