diff options
| author | Masayuki Morita | 2017-01-02 12:56:20 +0900 |
|---|---|---|
| committer | Masayuki Morita | 2017-01-02 15:56:55 +0900 |
| commit | b9cc52db455b879fa048421851d7bd43bddde817 (patch) | |
| tree | 4d8433b98d9726bedd702a394f766a89c10d2299 /Library/Homebrew/test | |
| parent | 3e0d54d8b9be1507c61e7a862379d7c9ad31fb8a (diff) | |
| download | brew-b9cc52db455b879fa048421851d7bd43bddde817.tar.bz2 | |
New feature: GitHubReleaseDownloadStrategy
GitHubReleaseDownloadStrategy downloads tarballs from GitHub Release assets.
To use it, add ":using => GitHubReleaseDownloadStrategy" to the URL section
of your formula. This download strategy uses GitHub access tokens (in the
environment variables GITHUB_TOKEN) to sign the request.
This strategy is suitable for corporate use just like S3DownloadStrategy,
because it lets you use a private GttHub repository for internal distribution.
It works with public one, but in that case simply use CurlDownloadStrategy.
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/download_strategies_test.rb | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/Library/Homebrew/test/download_strategies_test.rb b/Library/Homebrew/test/download_strategies_test.rb index 87218fb12..1df0267af 100644 --- a/Library/Homebrew/test/download_strategies_test.rb +++ b/Library/Homebrew/test/download_strategies_test.rb @@ -2,11 +2,12 @@ require "testing_env" require "download_strategy" class ResourceDouble - attr_reader :url, :specs, :version + attr_reader :url, :specs, :version, :mirrors def initialize(url = "http://example.com/foo.tar.gz", specs = {}) @url = url @specs = specs + @mirrors = [] end end @@ -60,6 +61,50 @@ class VCSDownloadStrategyTests < Homebrew::TestCase end end +class GitHubReleaseDownloadStrategyTests < Homebrew::TestCase + def setup + resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz") + ENV["GITHUB_TOKEN"] = "token" + @strategy = GitHubReleaseDownloadStrategy.new("foo", resource) + end + + def test_initialize + assert_equal "token", @strategy.instance_variable_get(:@github_token) + assert_equal "owner", @strategy.instance_variable_get(:@owner) + assert_equal "repo", @strategy.instance_variable_get(:@repo) + assert_equal "tag", @strategy.instance_variable_get(:@tag) + assert_equal "foo_v0.1.0_darwin_amd64.tar.gz", @strategy.instance_variable_get(:@filename) + end + + def test_asset_url + @strategy.stubs(:resolve_asset_id).returns(456) + expected = "https://token@api.github.com/repos/owner/repo/releases/assets/456" + assert_equal expected, @strategy.send(:asset_url) + end + + def test_resolve_asset_id + release_metadata = { + "assets" => [ + { + "id" => 123, + "name" => "foo_v0.1.0_linux_amd64.tar.gz", + }, + { + "id" => 456, + "name" => "foo_v0.1.0_darwin_amd64.tar.gz", + }, + ] + } + @strategy.stubs(:fetch_release_metadata).returns(release_metadata) + assert_equal 456, @strategy.send(:resolve_asset_id) + end + + def test_release_url + expected = "https://api.github.com/repos/owner/repo/releases/tags/tag" + assert_equal expected, @strategy.send(:release_url) + end +end + class GitDownloadStrategyTests < Homebrew::TestCase include FileUtils |
