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