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
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@a_pre = new_spec 'a', '1.a'
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
install_specs @a_pre
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem::Specification.remove_spec @b2
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
all = Gem::Specification.map { |spec|
|
|
|
|
Gem::NameTuple.new(spec.name, spec.version, spec.original_platform)
|
2011-05-31 23:45:05 -04:00
|
|
|
}.sort
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@prerelease_specs, @specs = all.partition { |g| g.prerelease? }
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: couldn't all of this come from the fake spec fetcher?
|
|
|
|
@latest_specs = Gem::Specification.latest_specs.sort.map { |spec|
|
2012-11-29 01:52:18 -05:00
|
|
|
Gem::NameTuple.new(spec.name, spec.version, spec.original_platform)
|
2011-05-31 23:45:05 -04:00
|
|
|
}
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
v = Gem.marshal_version
|
2012-11-29 01:52:18 -05:00
|
|
|
s_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@specs)))
|
|
|
|
l_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@latest_specs)))
|
|
|
|
p_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@prerelease_specs)))
|
2011-05-31 23:45:05 -04:00
|
|
|
@fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
|
|
|
|
@fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
|
|
|
|
@fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@sf = Gem::SpecFetcher.new
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
@released = Gem::NameTuple.from_list \
|
|
|
|
[["a", Gem::Version.new("1"), "ruby"],
|
|
|
|
["a", Gem::Version.new("2"), "ruby"],
|
|
|
|
["a_evil", Gem::Version.new("9"), "ruby"],
|
|
|
|
["c", Gem::Version.new("1.2"), "ruby"],
|
|
|
|
['dep_x', Gem::Version.new(1), 'ruby'],
|
|
|
|
["pl", Gem::Version.new("1"), "i386-linux"],
|
|
|
|
['x', Gem::Version.new(1), 'ruby']]
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_spec_for_dependency_all
|
2011-05-31 23:45:05 -04:00
|
|
|
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
|
|
|
|
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
|
|
|
|
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
|
|
|
|
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
|
|
|
|
@fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
expected = [[@a1.full_name, @source], [@a2.full_name, @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
|
2011-05-31 23:45:05 -04:00
|
|
|
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
|
|
|
|
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
|
|
|
|
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
|
|
|
|
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [[@a2.full_name, 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
|
2011-05-31 23:45:05 -04:00
|
|
|
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
|
|
|
|
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
|
|
|
|
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
|
|
|
|
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [[@a_pre.full_name, 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'
|
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
|
|
|
|
util_zip(Marshal.dump(@pl1))
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal [[@pl1.full_name, 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'
|
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
|
|
|
|
util_zip(Marshal.dump(@pl1))
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
assert_equal "i386-linux", errors[0].platforms.first
|
|
|
|
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
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
|
|
|
|
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
|
|
|
|
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
|
|
|
|
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
|
|
|
|
@fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
|
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
|
|
|
|
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
|
|
|
|
assert_equal @latest_specs, specs[@source].sort
|
2010-04-22 04:24:42 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_released
|
|
|
|
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
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal @released, specs[@source].sort
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_complete
|
|
|
|
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
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
comp = @prerelease_specs + @released
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal comp.sort, specs[@source].sort
|
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
|
|
|
|
v = Gem.marshal_version
|
|
|
|
@fetcher.data.delete "#{@gem_repo}prerelease_specs.#{v}.gz"
|
|
|
|
|
|
|
|
specs, _ = @sf.available_specs(:complete)
|
|
|
|
|
|
|
|
assert_equal [@source], specs.keys
|
|
|
|
|
|
|
|
comp = @released
|
|
|
|
|
|
|
|
assert_equal comp.sort, specs[@source].sort
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_available_specs_cache
|
|
|
|
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
|
|
|
|
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
|
|
|
|
specs, _ = @sf.available_specs(:prerelease)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal @prerelease_specs, specs[@source].sort
|
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
|
|
|
|
|