2011-01-29 02:46:47 +03:00
|
|
|
require 'rubygems/test_case'
|
2008-06-18 02:04:18 +04:00
|
|
|
require 'rubygems/spec_fetcher'
|
|
|
|
|
2011-01-29 02:46:47 +03:00
|
|
|
class TestGemSpecFetcher < Gem::TestCase
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@uri = URI.parse @gem_repo
|
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
@a_pre = new_spec 'a', '1.a'
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
install_specs @a_pre
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
Gem::Specification.remove_spec @b2
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
@specs = Gem::Specification.map { |spec|
|
2009-06-10 01:38:59 +04:00
|
|
|
[spec.name, spec.version, spec.original_platform]
|
2011-06-01 07:45:05 +04:00
|
|
|
}.sort
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2011-06-01 07: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|
|
|
|
|
[spec.name, spec.version, spec.original_platform]
|
|
|
|
}
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
prerelease = Gem::Specification.find_all { |s| s.version.prerelease? }
|
|
|
|
@prerelease_specs = prerelease.map { |spec|
|
|
|
|
[spec.name, spec.version, spec.original_platform]
|
|
|
|
}.sort
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
v = Gem.marshal_version
|
|
|
|
s_zip = util_gzip(Marshal.dump(@specs))
|
|
|
|
l_zip = util_gzip(Marshal.dump(@latest_specs))
|
|
|
|
p_zip = util_gzip(Marshal.dump(@prerelease_specs))
|
|
|
|
@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-10 01:38:59 +04:00
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
@sf = Gem::SpecFetcher.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_all
|
2011-06-01 07: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-18 02:04:18 +04:00
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'a', 1
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
specs_and_sources = @sf.fetch dep, true
|
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = [[@a1.full_name, @gem_repo], [@a2.full_name, @gem_repo]]
|
|
|
|
|
|
|
|
assert_equal expected, spec_names
|
|
|
|
|
|
|
|
assert_same specs_and_sources.first.last, specs_and_sources.last.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_latest
|
2011-06-01 07: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-18 02:04:18 +04:00
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'a', 1
|
|
|
|
specs_and_sources = @sf.fetch dep
|
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [[@a2.full_name, @gem_repo]], spec_names
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def test_fetch_prerelease
|
2011-06-01 07: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-10 01:38:59 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
specs_and_sources = @sf.fetch dep('a', '1.a'), false, true, true
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [[@a_pre.full_name, @gem_repo]], spec_names
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
def test_fetch_platform
|
|
|
|
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
|
|
|
|
specs_and_sources = @sf.fetch dep
|
|
|
|
|
|
|
|
spec_names = specs_and_sources.map do |spec, source_uri|
|
|
|
|
[spec.full_name, source_uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [[@pl1.full_name, @gem_repo]], spec_names
|
|
|
|
end
|
|
|
|
|
2010-04-22 12:24:42 +04:00
|
|
|
def test_fetch_with_errors_mismatched_platform
|
|
|
|
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
|
|
|
|
specs_and_sources, errors = @sf.fetch_with_errors dep
|
|
|
|
|
|
|
|
assert_equal 0, specs_and_sources.size
|
|
|
|
assert_equal 1, errors.size
|
|
|
|
|
|
|
|
assert_equal "i386-linux", errors[0].platforms.first
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
def test_fetch_spec
|
2010-02-22 05:52:35 +03:00
|
|
|
spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
|
2008-06-18 02:04:18 +04:00
|
|
|
@fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1))
|
|
|
|
|
|
|
|
spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
|
|
|
|
assert_equal @a1.full_name, spec.full_name
|
|
|
|
|
|
|
|
cache_dir = @sf.cache_dir URI.parse(spec_uri)
|
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
cache_file = File.join cache_dir, @a1.spec_name
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
assert File.exist?(cache_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_spec_cached
|
2010-02-22 05:52:35 +03:00
|
|
|
spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
|
2008-06-18 02:04:18 +04:00
|
|
|
@fetcher.data["#{spec_uri}.rz"] = nil
|
|
|
|
|
|
|
|
cache_dir = @sf.cache_dir URI.parse(spec_uri)
|
|
|
|
FileUtils.mkdir_p cache_dir
|
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
cache_file = File.join cache_dir, @a1.spec_name
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
open cache_file, 'wb' do |io|
|
|
|
|
Marshal.dump @a1, io
|
|
|
|
end
|
|
|
|
|
|
|
|
spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
|
|
|
|
assert_equal @a1.full_name, spec.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_spec_platform
|
|
|
|
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
|
|
|
|
util_zip(Marshal.dump(@pl1))
|
|
|
|
|
|
|
|
spec = @sf.fetch_spec ['pl', Gem::Version.new(1), 'i386-linux'], @uri
|
|
|
|
|
|
|
|
assert_equal @pl1.full_name, spec.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch_spec_platform_ruby
|
2010-02-22 05:52:35 +03:00
|
|
|
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
|
2008-06-18 02:04:18 +04:00
|
|
|
util_zip(Marshal.dump(@a1))
|
|
|
|
|
|
|
|
spec = @sf.fetch_spec ['a', Gem::Version.new(1), nil], @uri
|
|
|
|
assert_equal @a1.full_name, spec.full_name
|
|
|
|
|
|
|
|
spec = @sf.fetch_spec ['a', Gem::Version.new(1), ''], @uri
|
|
|
|
assert_equal @a1.full_name, spec.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_matching_all
|
|
|
|
dep = Gem::Dependency.new 'a', 1
|
|
|
|
specs = @sf.find_matching dep, true
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['a', Gem::Version.new(1), Gem::Platform::RUBY], @gem_repo],
|
|
|
|
[['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_matching_latest
|
|
|
|
dep = Gem::Dependency.new 'a', 1
|
|
|
|
specs = @sf.find_matching dep
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def test_find_matching_prerelease
|
|
|
|
dep = Gem::Dependency.new 'a', '1.a'
|
|
|
|
specs = @sf.find_matching dep, false, true, true
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['a', Gem::Version.new('1.a'), Gem::Platform::RUBY], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
def test_find_matching_platform
|
|
|
|
util_set_arch 'i386-linux'
|
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
|
|
|
specs = @sf.find_matching dep
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
|
|
|
|
util_set_arch 'i386-freebsd6'
|
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
|
|
|
specs = @sf.find_matching dep
|
|
|
|
|
|
|
|
assert_equal [], specs
|
|
|
|
end
|
|
|
|
|
2010-04-22 12:24:42 +04:00
|
|
|
def test_find_matching_with_errors_matched_platform
|
|
|
|
util_set_arch 'i386-linux'
|
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
|
|
|
specs, errors = @sf.find_matching_with_errors dep
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
assert_equal 0, errors.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_matching_with_errors_invalid_platform
|
|
|
|
util_set_arch 'hrpa-899'
|
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
|
|
|
specs, errors = @sf.find_matching_with_errors dep
|
|
|
|
|
|
|
|
assert_equal 0, specs.size
|
|
|
|
|
|
|
|
assert_equal 1, errors.size
|
|
|
|
|
|
|
|
assert_equal "i386-linux", errors[0].platforms.first
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
def test_find_all_platforms
|
|
|
|
util_set_arch 'i386-freebsd6'
|
|
|
|
|
|
|
|
dep = Gem::Dependency.new 'pl', 1
|
|
|
|
specs = @sf.find_matching dep, false, false
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, specs
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_list
|
|
|
|
specs = @sf.list
|
|
|
|
|
|
|
|
assert_equal [@uri], specs.keys
|
|
|
|
assert_equal @latest_specs, specs[@uri].sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_list_all
|
|
|
|
specs = @sf.list true
|
|
|
|
|
|
|
|
assert_equal [@uri], specs.keys
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
assert_equal([["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"],
|
|
|
|
["pl", Gem::Version.new("1"), "i386-linux"]],
|
2009-12-08 10:19:09 +03:00
|
|
|
specs[@uri].sort)
|
2008-06-18 02:04:18 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_list_cache
|
|
|
|
specs = @sf.list
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
refute specs[@uri].empty?
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
|
|
|
|
|
|
|
|
cached_specs = @sf.list
|
|
|
|
|
|
|
|
assert_equal specs, cached_specs
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_list_cache_all
|
|
|
|
specs = @sf.list true
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
refute specs[@uri].empty?
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
|
|
|
|
|
|
|
|
cached_specs = @sf.list true
|
|
|
|
|
|
|
|
assert_equal specs, cached_specs
|
|
|
|
end
|
|
|
|
|
2008-09-25 14:13:50 +04:00
|
|
|
def test_list_latest_all
|
|
|
|
specs = @sf.list false
|
|
|
|
|
|
|
|
assert_equal [@latest_specs], specs.values
|
|
|
|
|
|
|
|
specs = @sf.list true
|
|
|
|
|
2009-12-08 10:19:09 +03:00
|
|
|
assert_equal([[["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"],
|
|
|
|
["pl", Gem::Version.new("1"), "i386-linux"]]],
|
|
|
|
specs.values, 'specs file not loaded')
|
2008-09-25 14:13:50 +04:00
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def test_list_prerelease
|
|
|
|
specs = @sf.list false, true
|
|
|
|
|
|
|
|
assert_equal @prerelease_specs, specs[@uri].sort
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
def test_load_specs
|
|
|
|
expected = [
|
2011-06-01 07:45:05 +04:00
|
|
|
['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
|
2008-06-18 02:04:18 +04:00
|
|
|
['a', Gem::Version.new(1), Gem::Platform::RUBY],
|
|
|
|
['a', Gem::Version.new(2), Gem::Platform::RUBY],
|
2011-06-01 07:45:05 +04:00
|
|
|
['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
|
2008-06-18 02:04:18 +04:00
|
|
|
['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
|
|
|
|
['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
|
|
|
|
['pl', Gem::Version.new(1), 'i386-linux'],
|
|
|
|
]
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
assert_equal expected, @sf.load_specs(@uri, 'specs')
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
|
|
|
|
assert File.exist?(cache_dir), "#{cache_dir} does not exist"
|
|
|
|
|
|
|
|
cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
|
|
|
|
assert File.exist?(cache_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_load_specs_cached
|
2008-09-25 14:13:50 +04:00
|
|
|
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
|
2008-06-18 02:04:18 +04:00
|
|
|
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
|
|
|
|
' ' * Marshal.dump(@latest_specs).length
|
|
|
|
|
2008-06-19 22:15:26 +04:00
|
|
|
cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p cache_dir
|
|
|
|
|
|
|
|
cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
|
|
|
|
|
|
|
|
open cache_file, 'wb' do |io|
|
|
|
|
Marshal.dump @latest_specs, io
|
|
|
|
end
|
|
|
|
|
2008-06-26 06:06:00 +04:00
|
|
|
latest_specs = @sf.load_specs @uri, 'latest_specs'
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2008-06-26 06:06:00 +04:00
|
|
|
assert_equal @latest_specs, latest_specs
|
2008-06-18 02:04:18 +04:00
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def test_load_specs_cached_empty
|
|
|
|
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
|
|
|
|
proc do
|
|
|
|
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
|
|
|
|
util_gzip(Marshal.dump(@latest_specs))
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p cache_dir
|
|
|
|
|
|
|
|
cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
|
|
|
|
|
|
|
|
open cache_file, 'wb' do |io|
|
|
|
|
io.write Marshal.dump(@latest_specs)[0, 10]
|
|
|
|
end
|
|
|
|
|
|
|
|
latest_specs = @sf.load_specs @uri, 'latest_specs'
|
|
|
|
|
|
|
|
assert_equal @latest_specs, latest_specs
|
|
|
|
end
|
|
|
|
|
2011-03-07 11:44:45 +03:00
|
|
|
def test_cache_dir_escapes_windows_paths
|
|
|
|
uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
|
2011-03-10 01:32:29 +03:00
|
|
|
cache_dir = @sf.cache_dir(uri).gsub(@sf.dir, '')
|
|
|
|
assert cache_dir !~ /:/, "#{cache_dir} should not contain a :"
|
2011-03-07 11:44:45 +03:00
|
|
|
end
|
2008-06-18 02:04:18 +04:00
|
|
|
end
|
|
|
|
|