[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:30:21 UTC 2010


The following commit has been merged in the upstream branch:
commit 2b8125ccb75402b4ced3c2938243ec5309e78766
Author: Rein Henrichs <reinh at reinh.com>
Date:   Tue Mar 23 14:34:01 2010 -0700

    Replace test/unit file write test with spec

diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index b5963a6..206a50e 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 69a893e..75ed96a 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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list