Test coverage for DownloadStrategyDetector
While at it, make it use class methods instead; no reason to instantiate an object for this. Eventually there should be some functional tests for the individual strategies as well. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
bab29bab72
commit
39ec66614b
@ -586,23 +586,20 @@ class FossilDownloadStrategy < AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
class DownloadStrategyDetector
|
class DownloadStrategyDetector
|
||||||
def initialize url, strategy=nil
|
def self.detect(url, strategy=nil)
|
||||||
@url = url
|
if strategy.is_a? Class and strategy.ancestors.include? AbstractDownloadStrategy
|
||||||
@strategy = strategy
|
strategy
|
||||||
end
|
elsif strategy.is_a? Symbol
|
||||||
|
detect_from_symbol(strategy)
|
||||||
def detect
|
else
|
||||||
if @strategy.is_a? Class and @strategy.ancestors.include? AbstractDownloadStrategy
|
detect_from_url(url)
|
||||||
@strategy
|
|
||||||
elsif @strategy.is_a? Symbol then detect_from_symbol
|
|
||||||
else detect_from_url
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def detect_from_url
|
def self.detect_from_url(url)
|
||||||
case @url
|
case url
|
||||||
# We use a special URL pattern for cvs
|
# We use a special URL pattern for cvs
|
||||||
when %r[^cvs://] then CVSDownloadStrategy
|
when %r[^cvs://] then CVSDownloadStrategy
|
||||||
# Standard URLs
|
# Standard URLs
|
||||||
@ -628,8 +625,8 @@ class DownloadStrategyDetector
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def detect_from_symbol
|
def self.detect_from_symbol(symbol)
|
||||||
case @strategy
|
case symbol
|
||||||
when :bzr then BazaarDownloadStrategy
|
when :bzr then BazaarDownloadStrategy
|
||||||
when :curl then CurlDownloadStrategy
|
when :curl then CurlDownloadStrategy
|
||||||
when :cvs then CVSDownloadStrategy
|
when :cvs then CVSDownloadStrategy
|
||||||
@ -639,7 +636,7 @@ class DownloadStrategyDetector
|
|||||||
when :post then CurlPostDownloadStrategy
|
when :post then CurlPostDownloadStrategy
|
||||||
when :svn then SubversionDownloadStrategy
|
when :svn then SubversionDownloadStrategy
|
||||||
else
|
else
|
||||||
raise "Unknown download strategy #{@strategy} was requested."
|
raise "Unknown download strategy #{strategy} was requested."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class SoftwareSpec
|
|||||||
end
|
end
|
||||||
|
|
||||||
def download_strategy
|
def download_strategy
|
||||||
@download_strategy ||= DownloadStrategyDetector.new(@url, @using).detect
|
@download_strategy ||= DownloadStrategyDetector.detect(@url, @using)
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_download_integrity fn
|
def verify_download_integrity fn
|
||||||
|
|||||||
19
Library/Homebrew/test/test_download_strategies.rb
Normal file
19
Library/Homebrew/test/test_download_strategies.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
require 'testing_env'
|
||||||
|
require 'download_strategy'
|
||||||
|
require 'bottles' # XXX: hoist these regexps into constants in Pathname?
|
||||||
|
|
||||||
|
class DownloadStrategyDetectorTests < Test::Unit::TestCase
|
||||||
|
def setup
|
||||||
|
@d = DownloadStrategyDetector.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_detect_git_download_startegy
|
||||||
|
@d = DownloadStrategyDetector.detect("git://foo.com/bar.git")
|
||||||
|
assert_equal GitDownloadStrategy, @d
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_default_to_curl_strategy
|
||||||
|
@d = DownloadStrategyDetector.detect(Object.new)
|
||||||
|
assert_equal CurlDownloadStrategy, @d
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user