2007-11-10 02:48:56 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
|
|
|
require 'rubygems/source_info_cache_entry'
|
|
|
|
|
|
|
|
class TestGemSourceInfoCacheEntry < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@si = Gem::SourceIndex.new
|
|
|
|
@si.add_spec @a1
|
2007-11-10 02:48:56 -05:00
|
|
|
@sic_e = Gem::SourceInfoCacheEntry.new @si, @si.dump.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_refresh
|
|
|
|
@fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
|
2008-03-31 18:40:06 -04:00
|
|
|
proc { raise }
|
2007-11-10 02:48:56 -05:00
|
|
|
@fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@sic_e.refresh @gem_repo, true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_refresh_all
|
|
|
|
@si.add_spec @a2
|
|
|
|
|
|
|
|
a1_name = @a1.full_name
|
|
|
|
a2_name = @a2.full_name
|
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}/quick/index.rz"] =
|
|
|
|
util_zip [a1_name, a2_name].join("\n")
|
|
|
|
@fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
|
|
|
|
@fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
|
|
|
|
@fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
|
|
|
|
@fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
|
|
|
|
Marshal.dump @si
|
|
|
|
|
|
|
|
sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
sic_e.refresh @gem_repo, false
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
sic_e.refresh @gem_repo, true
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [a1_name, a2_name], sic_e.source_index.map { |n,| n }.sort
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_refresh_bad_uri
|
|
|
|
assert_raise URI::BadURIError do
|
2008-03-31 18:40:06 -04:00
|
|
|
@sic_e.refresh 'gems.example.com', true
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_refresh_update
|
2008-03-31 18:40:06 -04:00
|
|
|
si = Gem::SourceIndex.new
|
|
|
|
si.add_spec @a1
|
|
|
|
si.add_spec @b2
|
2007-11-10 02:48:56 -05:00
|
|
|
@fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
|
|
|
|
|
|
|
|
use_ui @ui do
|
2008-03-31 18:40:06 -04:00
|
|
|
@sic_e.refresh @gem_repo, true
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
new_gem = @sic_e.source_index.specification(@b2.full_name)
|
|
|
|
assert_equal @b2.full_name, new_gem.full_name
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|