2007-11-10 02:48:56 -05:00
|
|
|
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
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] =
|
2008-03-31 18:40:06 -04:00
|
|
|
proc { raise }
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = @si.dump
|
2007-11-10 02:48:56 -05:00
|
|
|
|
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
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher.data["#{@gem_repo}quick/index.rz"] =
|
2008-03-31 18:40:06 -04:00
|
|
|
util_zip [a1_name, a2_name].join("\n")
|
2008-06-17 18:04:18 -04:00
|
|
|
@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}"] =
|
2008-03-31 18:40:06 -04:00
|
|
|
Marshal.dump @si
|
|
|
|
|
|
|
|
sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal [], sic_e.source_index.map { |n,| n }
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_ui @ui do
|
2008-06-17 18:04:18 -04:00
|
|
|
assert 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
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises 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
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|