diff options
| author | Vlad Shablinsky | 2016-05-25 20:11:27 +0300 |
|---|---|---|
| committer | Xu Cheng | 2016-07-06 16:19:49 +0800 |
| commit | 0b2cc5c20db30f5d0046091f8c2318752f7b0659 (patch) | |
| tree | fcea77766869c6c9a2b3b06524fcce55dd939af6 /Library | |
| parent | 2f5f352baa95ce9cc6b4e0007ee2fc028ffc2a1a (diff) | |
| download | brew-0b2cc5c20db30f5d0046091f8c2318752f7b0659.tar.bz2 | |
test_download_strategies: add git tests
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/test_download_strategies.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_download_strategies.rb b/Library/Homebrew/test/test_download_strategies.rb index 24f38ad2d..9a53d48eb 100644 --- a/Library/Homebrew/test/test_download_strategies.rb +++ b/Library/Homebrew/test/test_download_strategies.rb @@ -60,6 +60,69 @@ class VCSDownloadStrategyTests < Homebrew::TestCase end end +class GitDownloadStrategyTests < Homebrew::TestCase + include FileUtils + + def setup + resource = ResourceDouble.new("https://github.com/homebrew/foo") + @commit_id = 1 + @strategy = GitDownloadStrategy.new("baz", resource) + @cached_location = @strategy.cached_location + mkpath @cached_location + touch @cached_location/"README" + end + + def teardown + rmtree @cached_location + end + + def git_commit_all + shutup do + system "git", "add", "--all" + system "git", "commit", "-m", "commit number #{@commit_id}" + @commit_id += 1 + end + end + + def inside_repo_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 + 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" + end + git_commit_all + end + end + + def test_source_modified_time + setup_git_repo + assert_equal 1242860651, @strategy.source_modified_time.to_i + end + + def test_last_commit + setup_git_repo + inside_repo_using_git_env do + touch "LICENSE" + git_commit_all + end + assert_equal "c50c79b", @strategy.last_commit + end +end + class DownloadStrategyDetectorTests < Homebrew::TestCase def setup @d = DownloadStrategyDetector.new |
