Apply and add new download strategy tests

This commit is contained in:
Vlad Shablinsky 2016-07-27 17:49:43 +03:00 committed by Xu Cheng
parent 5ddee3502e
commit 00f37d6778
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE

View File

@ -69,7 +69,6 @@ class GitDownloadStrategyTests < Homebrew::TestCase
@strategy = GitDownloadStrategy.new("baz", resource)
@cached_location = @strategy.cached_location
mkpath @cached_location
touch @cached_location/"README"
end
def teardown
@ -84,30 +83,39 @@ class GitDownloadStrategyTests < Homebrew::TestCase
end
end
def inside_repo_using_git_env
def using_git_env
initial_env = ENV.to_hash
%w[AUTHOR COMMITTER].each do |role|
ENV["GIT_#{role}_NAME"] = "brew tests"
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
end
@cached_location.cd do
yield
end
yield
ensure
ENV.replace(initial_env)
end
def setup_git_repo
inside_repo_using_git_env do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
using_git_env do
@cached_location.cd do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
end
touch "README"
git_commit_all
end
git_commit_all
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
setup_git_repo
assert_equal 1242860651, @strategy.source_modified_time.to_i
@ -115,12 +123,41 @@ class GitDownloadStrategyTests < Homebrew::TestCase
def test_last_commit
setup_git_repo
inside_repo_using_git_env do
touch "LICENSE"
git_commit_all
using_git_env do
@cached_location.cd do
touch "LICENSE"
git_commit_all
end
end
assert_equal "c50c79b", @strategy.last_commit
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
class DownloadStrategyDetectorTests < Homebrew::TestCase
@ -133,6 +170,11 @@ class DownloadStrategyDetectorTests < Homebrew::TestCase
assert_equal GitDownloadStrategy, @d
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
@d = DownloadStrategyDetector.detect(Object.new)
assert_equal CurlDownloadStrategy, @d