diff options
author | Luke Kanies <luke@madstop.com> | 2008-02-21 23:18:40 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-02-21 23:18:40 -0500 |
commit | b06767ee2d7c22c27d746d3e8d1b6effa37deaa6 (patch) | |
tree | 1b31ca784215113e5962310299826616c8768cd7 /test | |
parent | 5e18b8dc91b2313a96dd3a9ff9cb0a88bfe0d6a0 (diff) | |
download | puppet-b06767ee2d7c22c27d746d3e8d1b6effa37deaa6.tar.gz puppet-b06767ee2d7c22c27d746d3e8d1b6effa37deaa6.tar.xz puppet-b06767ee2d7c22c27d746d3e8d1b6effa37deaa6.zip |
Quashed commit of my fixes for #1010.
Diffstat (limited to 'test')
-rwxr-xr-x | test/ral/types/file.rb | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index aa2e63a89..c7872ccea 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -9,9 +9,7 @@ require 'fileutils' class TestFile < Test::Unit::TestCase include PuppetTest::Support::Utils include PuppetTest::FileTesting - # hmmm - # this is complicated, because we store references to the created - # objects in a central store + def mkfile(hash) file = nil assert_nothing_raised { @@ -21,8 +19,6 @@ class TestFile < Test::Unit::TestCase end def mktestfile - # because luke's home directory is on nfs, it can't be used for testing - # as root tmpfile = tempfile() File.open(tmpfile, "w") { |f| f.puts rand(100) } @@tmpfiles.push tmpfile @@ -407,8 +403,7 @@ class TestFile < Test::Unit::TestCase assert(events) - assert(! events.include?(:file_changed), - "File incorrectly changed") + assert(! events.include?(:file_changed), "File incorrectly changed") assert_events([], file) # We have to sleep because the time resolution of the time-based @@ -1103,7 +1098,7 @@ class TestFile < Test::Unit::TestCase File.open(file, "w") { |f| f.puts "more text" } assert_events([], obj) obj[:links] = :follow - assert_events([:file_changed], obj) + assert_events([:file_changed, :file_changed], obj) end # If both 'ensure' and 'content' are used, make sure that all of the other @@ -1292,6 +1287,7 @@ class TestFile < Test::Unit::TestCase :title => "localfile", :path => localfile, :content => "rahtest", + :ensure => :file, :backup => false ) @@ -1304,8 +1300,8 @@ class TestFile < Test::Unit::TestCase config.apply assert(FileTest.exists?(dsourcefile), "File did not get copied") - assert(FileTest.exists?(localfile), "File did not get created") - assert(FileTest.exists?(purgee), "File got prematurely purged") + assert(FileTest.exists?(localfile), "Local file did not get created") + assert(FileTest.exists?(purgee), "Purge target got prematurely purged") assert_nothing_raised { destobj[:purge] = true } config.apply @@ -1822,5 +1818,26 @@ class TestFile < Test::Unit::TestCase obj = Puppet::Type.newfile(:path => '/', :mode => 0755) assert_equal("/", obj.title, "/ directory was changed to empty string") end -end + # #1010 and #1037 -- write should fail if the written checksum does not + # match the file we thought we were writing. + def test_write_validates_checksum + file = tempfile + inst = Puppet::Type.newfile(:path => file, :content => "something") + + tmpfile = file + ".puppettmp" + + wh = mock 'writehandle', :print => nil + rh = mock 'readhandle' + rh.expects(:read).with(512).times(2).returns("other").then.returns(nil) + File.expects(:open).with { |*args| args[0] == tmpfile and args[1] != "r" }.yields(wh) + File.expects(:open).with { |*args| args[0] == tmpfile and args[1] == "r" }.yields(rh) + + File.stubs(:rename) + FileTest.stubs(:exist?).returns(true) + FileTest.stubs(:file?).returns(true) + + inst.expects(:fail) + inst.write("something", :whatever) + end +end |