2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2008-06-17 18:04:18 -04:00
|
|
|
require 'rubygems/spec_fetcher'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemSpecFetcher < Gem::TestCase
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def tuple(*args)
|
|
|
|
Gem::NameTuple.new(*args)
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@uri = URI.parse @gem_repo
|
2012-11-29 01:52:18 -05:00
|
|
|
@source = Gem::Source.new(@uri)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
@sf = Gem::SpecFetcher.new
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def test_initialize
|
|
|
|
fetcher = Gem::SpecFetcher.new
|
|
|
|
|
|
|
|
assert_same Gem.sources, fetcher.sources
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_source
|
|
|
|
alternate = 'http://alternate.example'
|
|
|
|
fetcher = Gem::SpecFetcher.new alternate
|
|
|
|
|
|
|
|
refute_same Gem.sources, fetcher.sources
|
|
|
|
|
|
|
|
assert_equal alternate, fetcher.sources
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_nonexistent_home_dir
|
2013-10-18 17:56:18 -04:00
|
|
|
FileUtils.rmdir Gem.user_home
|
|
|
|
|
|
|
|
assert Gem::SpecFetcher.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_unwritable_home_dir
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
|
|
|
|
|
|
|
FileUtils.chmod 0000, Gem.user_home
|
|
|
|
|
|
|
|
begin
|
|
|
|
assert Gem::SpecFetcher.new
|
|
|
|
ensure
|
|
|
|
FileUtils.chmod 0755, Gem.user_home
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_all
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
fetcher.spec 'a', '3.a'
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
dep = Gem::Dependency.new 'a', ">= 1"
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs_and_sources, _ = @sf.spec_for_dependency dep
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
expected = [['a-1', @source], ['a-2', @source]]
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
assert_equal expected, spec_names
|
|
|
|
|
|
|
|
assert_same specs_and_sources.first.last, specs_and_sources.last.last
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_latest
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
fetcher.spec 'a', '3.a'
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
dep = Gem::Dependency.new 'a'
|
|
|
|
specs_and_sources, _ = @sf.spec_for_dependency dep
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
assert_equal [['a-2', Gem::Source.new(@gem_repo)]],
|
|
|
|
spec_names
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_prerelease
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', '1.a'
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs_and_sources, _ = @sf.spec_for_dependency dep('a', '1.a')
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
assert_equal [['a-1.a', Gem::Source.new(@gem_repo)]], spec_names
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_platform
|
2008-06-17 18:04:18 -04:00
|
|
|
util_set_arch 'i386-linux'
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
2012-11-29 01:52:18 -05:00
|
|
|
specs_and_sources, _ = @sf.spec_for_dependency dep
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
assert_equal [['pl-1-x86-linux', Gem::Source.new(@gem_repo)]],
|
|
|
|
spec_names
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_mismatched_platform
|
2010-04-22 04:24:42 -04:00
|
|
|
util_set_arch 'hrpa-989'
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
2010-04-22 04:24:42 -04:00
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
2012-11-29 01:52:18 -05:00
|
|
|
specs_and_sources, errors = @sf.spec_for_dependency dep
|
2010-04-22 04:24:42 -04:00
|
|
|
|
|
|
|
assert_equal 0, specs_and_sources.size
|
|
|
|
assert_equal 1, errors.size
|
2013-07-08 18:41:03 -04:00
|
|
|
pmm = errors.first
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2013-07-08 18:41:03 -04:00
|
|
|
assert_equal "i386-linux", pmm.platforms.first
|
|
|
|
assert_equal "Found pl (1), but was for platform i386-linux", pmm.wordy
|
2010-04-22 04:24:42 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_bad_fetch_spec
|
|
|
|
src = Gem::Source.new(@gem_repo)
|
|
|
|
def src.fetch_spec(name)
|
|
|
|
raise Gem::RemoteFetcher::FetchError.new("bad news from the internet", @uri)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
Gem.sources.replace [src]
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
fetcher.spec 'a', '3.a'
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
dep = Gem::Dependency.new 'a', ">= 1"
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs_and_sources, errors = @sf.spec_for_dependency dep
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [], specs_and_sources
|
|
|
|
sfp = errors.first
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_kind_of Gem::SourceFetchProblem, sfp
|
|
|
|
assert_equal src, sfp.source
|
|
|
|
assert_equal "bad news from the internet (#{@gem_repo})", sfp.error.message
|
2010-04-22 04:24:42 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_latest
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
fetcher.spec 'a', '3.a'
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:latest)
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [@source], specs.keys
|
2013-11-11 19:16:41 -05:00
|
|
|
|
|
|
|
expected = Gem::NameTuple.from_list \
|
|
|
|
[['a', v(2), Gem::Platform::RUBY],
|
|
|
|
['pl', v(1), 'i386-linux']]
|
|
|
|
|
|
|
|
assert_equal expected, specs[@source]
|
2010-04-22 04:24:42 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_released
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:released)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [@source], specs.keys
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
expected = Gem::NameTuple.from_list \
|
|
|
|
[['a', v(1), Gem::Platform::RUBY],
|
|
|
|
['pl', v(1), 'i386-linux']]
|
|
|
|
|
|
|
|
assert_equal expected, specs[@source]
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_complete
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:complete)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [@source], specs.keys
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
expected = Gem::NameTuple.from_list \
|
|
|
|
[['a', v(1), Gem::Platform::RUBY],
|
|
|
|
['a', v('2.a'), Gem::Platform::RUBY],
|
|
|
|
['b', v(2), Gem::Platform::RUBY],
|
|
|
|
['pl', v(1), 'i386-linux']]
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
assert_equal expected, specs[@source]
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 22:28:04 -05:00
|
|
|
def test_available_specs_complete_handles_no_prerelease
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2012-11-29 22:28:04 -05:00
|
|
|
v = Gem.marshal_version
|
|
|
|
@fetcher.data.delete "#{@gem_repo}prerelease_specs.#{v}.gz"
|
|
|
|
|
|
|
|
specs, _ = @sf.available_specs(:complete)
|
|
|
|
|
|
|
|
assert_equal [@source], specs.keys
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
expected = Gem::NameTuple.from_list \
|
|
|
|
[['a', v(1), Gem::Platform::RUBY],
|
|
|
|
['b', v(2), Gem::Platform::RUBY],
|
|
|
|
['pl', v(1), 'i386-linux']]
|
|
|
|
|
|
|
|
assert_equal expected, specs[@source]
|
2012-11-29 22:28:04 -05:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_cache
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:latest)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
refute specs[@source].empty?
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
cached_specs, _ = @sf.available_specs(:latest)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
assert_equal specs, cached_specs
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_cache_released
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:released)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
refute specs[@source].empty?
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
cached_specs, _ = @sf.available_specs(:released)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
assert_equal specs, cached_specs
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_prerelease
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, _ = @sf.available_specs(:prerelease)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
expected = Gem::NameTuple.from_list \
|
|
|
|
[['a', v('2.a'), Gem::Platform::RUBY]]
|
|
|
|
|
|
|
|
assert_equal expected, specs[@source]
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_with_bad_source
|
|
|
|
Gem.sources.replace ["http://not-there.nothing"]
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs, errors = @sf.available_specs(:latest)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal({}, specs)
|
|
|
|
assert_kind_of Gem::SourceFetchProblem, errors.first
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|