Apply and add new download strategy tests
This commit is contained in:
parent
5ddee3502e
commit
00f37d6778
@ -69,7 +69,6 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
@strategy = GitDownloadStrategy.new("baz", resource)
|
@strategy = GitDownloadStrategy.new("baz", resource)
|
||||||
@cached_location = @strategy.cached_location
|
@cached_location = @strategy.cached_location
|
||||||
mkpath @cached_location
|
mkpath @cached_location
|
||||||
touch @cached_location/"README"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@ -84,30 +83,39 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def inside_repo_using_git_env
|
def using_git_env
|
||||||
initial_env = ENV.to_hash
|
initial_env = ENV.to_hash
|
||||||
%w[AUTHOR COMMITTER].each do |role|
|
%w[AUTHOR COMMITTER].each do |role|
|
||||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||||
end
|
end
|
||||||
@cached_location.cd do
|
yield
|
||||||
yield
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
ENV.replace(initial_env)
|
ENV.replace(initial_env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_git_repo
|
def setup_git_repo
|
||||||
inside_repo_using_git_env do
|
using_git_env do
|
||||||
shutup do
|
@cached_location.cd do
|
||||||
system "git", "init"
|
shutup do
|
||||||
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
system "git", "init"
|
||||||
|
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
||||||
|
end
|
||||||
|
touch "README"
|
||||||
|
git_commit_all
|
||||||
end
|
end
|
||||||
git_commit_all
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_github_git_download_strategy_user_repo
|
||||||
|
resource = ResourceDouble.new("https://github.com/homebrew/brew.git")
|
||||||
|
strategy = GitHubGitDownloadStrategy.new("brew", resource)
|
||||||
|
|
||||||
|
assert_equal strategy.instance_variable_get(:@user), "homebrew"
|
||||||
|
assert_equal strategy.instance_variable_get(:@repo), "brew"
|
||||||
|
end
|
||||||
|
|
||||||
def test_source_modified_time
|
def test_source_modified_time
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
assert_equal 1242860651, @strategy.source_modified_time.to_i
|
assert_equal 1242860651, @strategy.source_modified_time.to_i
|
||||||
@ -115,12 +123,41 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
|
|
||||||
def test_last_commit
|
def test_last_commit
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
inside_repo_using_git_env do
|
using_git_env do
|
||||||
touch "LICENSE"
|
@cached_location.cd do
|
||||||
git_commit_all
|
touch "LICENSE"
|
||||||
|
git_commit_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
assert_equal "c50c79b", @strategy.last_commit
|
assert_equal "c50c79b", @strategy.last_commit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fetch_last_commit
|
||||||
|
remote_repo = HOMEBREW_PREFIX.join("remote_repo")
|
||||||
|
remote_repo.mkdir
|
||||||
|
|
||||||
|
resource = ResourceDouble.new("file://#{remote_repo}")
|
||||||
|
resource.instance_variable_set(:@version, Version.create("HEAD"))
|
||||||
|
@strategy = GitDownloadStrategy.new("baz", resource)
|
||||||
|
|
||||||
|
using_git_env do
|
||||||
|
remote_repo.cd do
|
||||||
|
shutup do
|
||||||
|
system "git", "init"
|
||||||
|
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
||||||
|
end
|
||||||
|
touch "README"
|
||||||
|
git_commit_all
|
||||||
|
touch "LICENSE"
|
||||||
|
git_commit_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@strategy.shutup!
|
||||||
|
assert_equal "c50c79b", @strategy.fetch_last_commit
|
||||||
|
ensure
|
||||||
|
remote_repo.rmtree if remote_repo.directory?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DownloadStrategyDetectorTests < Homebrew::TestCase
|
class DownloadStrategyDetectorTests < Homebrew::TestCase
|
||||||
@ -133,6 +170,11 @@ class DownloadStrategyDetectorTests < Homebrew::TestCase
|
|||||||
assert_equal GitDownloadStrategy, @d
|
assert_equal GitDownloadStrategy, @d
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_detect_github_git_download_strategy
|
||||||
|
@d = DownloadStrategyDetector.detect("https://github.com/homebrew/brew.git")
|
||||||
|
assert_equal GitHubGitDownloadStrategy, @d
|
||||||
|
end
|
||||||
|
|
||||||
def test_default_to_curl_strategy
|
def test_default_to_curl_strategy
|
||||||
@d = DownloadStrategyDetector.detect(Object.new)
|
@d = DownloadStrategyDetector.detect(Object.new)
|
||||||
assert_equal CurlDownloadStrategy, @d
|
assert_equal CurlDownloadStrategy, @d
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user