summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRein Henrichs <reinh@reinh.com>2010-03-23 14:34:01 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit2b8125ccb75402b4ced3c2938243ec5309e78766 (patch)
tree74e8d41a985c35900dcf511345a04502d976140f
parent164f1ce85bad49c7e197deeb452828c94539e06e (diff)
downloadpuppet-2b8125ccb75402b4ced3c2938243ec5309e78766.tar.gz
puppet-2b8125ccb75402b4ced3c2938243ec5309e78766.tar.xz
puppet-2b8125ccb75402b4ced3c2938243ec5309e78766.zip
Replace test/unit file write test with spec
-rwxr-xr-xspec/unit/type/file.rb47
-rwxr-xr-xtest/ral/type/file.rb21
2 files changed, 36 insertions, 32 deletions
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index b5963a666..206a50ed9 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -16,6 +16,42 @@ describe Puppet::Type.type(:file) do
@file.catalog = @catalog
end
+ describe "#write" do
+
+ it "should propagate failures encountered when renaming the temporary file" do
+ File.stubs(:open)
+
+ File.expects(:rename).raises ArgumentError
+ file = Puppet::Type::File.new(:name => "/my/file", :backup => "puppet")
+
+ lambda { file.write("something", :content) }.should raise_error(Puppet::Error)
+ end
+
+ describe "when validating the checksum" do
+ before { @file.stubs(:validate_checksum?).returns(true) }
+
+ it "should fail if the checksum property and content checksums do not match" do
+ property = stub('checksum_property', :checktype => :md5, :md5 => 'checksum_a', :getsum => 'checksum_b')
+ @file.stubs(:property).with(:checksum).returns(property)
+
+ @file.stubs(:validate_checksum?).returns(true)
+ lambda { @file.write "something", :NOTUSED }.should raise_error(Puppet::Error)
+ end
+ end
+
+ describe "when not validating the checksum" do
+ before { @file.stubs(:validate_checksum?).returns(false) }
+
+ it "should not fail if the checksum property and content checksums do not match" do
+ property = stub('checksum_property', :checktype => :md5, :md5 => 'checksum_a', :getsum => 'checksum_b')
+ @file.stubs(:property).with(:checksum).returns(property)
+
+ lambda { @file.write "something", :NOTUSED }.should_not raise_error(Puppet::Error)
+ end
+
+ end
+ end
+
it "should have a method for determining if the file is present" do
@file.must respond_to(:exist?)
end
@@ -771,15 +807,4 @@ describe Puppet::Type.type(:file) do
file.finish
end
end
-
- describe "when writing the file" do
- it "should propagate failures encountered when renaming the temporary file" do
- File.stubs(:open)
-
- File.expects(:rename).raises ArgumentError
- file = Puppet::Type::File.new(:name => "/my/file", :backup => "puppet")
-
- lambda { file.write("something", :content) }.should raise_error(Puppet::Error)
- end
- end
end
diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb
index 69a893e31..75ed96a8d 100755
--- a/test/ral/type/file.rb
+++ b/test/ral/type/file.rb
@@ -978,25 +978,4 @@ class TestFile < Test::Unit::TestCase
assert_equal("/", obj.title, "/ directory was changed to empty string")
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(4096).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