aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/download_strategies_test.rb47
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