Resource: push conditional down into #verify_download_integrity
This commit is contained in:
parent
a5b2814770
commit
2dd44f7791
@ -48,8 +48,7 @@ class Resource
|
||||
# If block is given, yield to that block
|
||||
# A target or a block must be given, but not both
|
||||
def stage(target=nil)
|
||||
fetched = fetch
|
||||
verify_download_integrity(fetched) if fetched.respond_to?(:file?) and fetched.file?
|
||||
verify_download_integrity(fetch)
|
||||
mktemp(download_name) do
|
||||
downloader.stage
|
||||
if block_given?
|
||||
@ -75,7 +74,9 @@ class Resource
|
||||
end
|
||||
|
||||
def verify_download_integrity fn
|
||||
fn.verify_checksum(checksum)
|
||||
if fn.respond_to?(:file?) && fn.file?
|
||||
fn.verify_checksum(checksum)
|
||||
end
|
||||
rescue ChecksumMissingError
|
||||
opoo "Cannot verify integrity of #{fn.basename}"
|
||||
puts "A checksum was not provided for this resource"
|
||||
|
||||
@ -106,15 +106,15 @@ class ResourceTests < Test::Unit::TestCase
|
||||
fn = Pathname.new('test')
|
||||
checksum = @resource.sha1('baadidea'*5)
|
||||
|
||||
fn.expects(:verify_checksum).
|
||||
with(checksum).raises(ChecksumMissingError)
|
||||
fn.stubs(:file? => true)
|
||||
fn.expects(:verify_checksum).raises(ChecksumMissingError)
|
||||
fn.expects(:sha1)
|
||||
|
||||
shutup { @resource.verify_download_integrity(fn) }
|
||||
end
|
||||
|
||||
def test_verify_download_integrity_mismatch
|
||||
fn = Object.new
|
||||
fn = stub(:file? => true)
|
||||
checksum = @resource.sha1('baadidea'*5)
|
||||
|
||||
fn.expects(:verify_checksum).with(checksum).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user