diff options
| author | Vlad Shablinsky | 2016-07-27 17:49:43 +0300 |
|---|---|---|
| committer | Xu Cheng | 2016-08-06 21:25:56 +0800 |
| commit | 00f37d67787ff5e06e754680d23ea015699ea6f7 (patch) | |
| tree | b17185c795ffb2f7b5136a30e4ffd45e4bf07150 /Library | |
| parent | 5ddee3502e7c8dd67b1fec4de2f72df6fd16cc94 (diff) | |
| download | brew-00f37d67787ff5e06e754680d23ea015699ea6f7.tar.bz2 | |
Apply and add new download strategy tests
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/test_download_strategies.rb | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/Library/Homebrew/test/test_download_strategies.rb b/Library/Homebrew/test/test_download_strategies.rb index 9a53d48eb..3f371d461 100644 --- a/Library/Homebrew/test/test_download_strategies.rb +++ b/Library/Homebrew/test/test_download_strategies.rb @@ -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 |
