2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/source_info_cache_entry'
5 class TestGemSourceInfoCacheEntry < RubyGemTestCase
10 util_setup_fake_fetcher
12 @si = Gem::SourceIndex.new
14 @sic_e = Gem::SourceInfoCacheEntry.new @si, @si.dump.size
18 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
20 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
23 @sic_e.refresh @gem_repo, true
30 a1_name = @a1.full_name
31 a2_name = @a2.full_name
33 @fetcher.data["#{@gem_repo}/quick/index.rz"] =
34 util_zip [a1_name, a2_name].join("\n")
35 @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
36 @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
37 @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
38 @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
41 sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
44 sic_e.refresh @gem_repo, false
47 assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
50 sic_e.refresh @gem_repo, true
53 assert_equal [a1_name, a2_name], sic_e.source_index.map { |n,| n }.sort
56 def test_refresh_bad_uri
57 assert_raise URI::BadURIError do
58 @sic_e.refresh 'gems.example.com', true
62 def test_refresh_update
63 si = Gem::SourceIndex.new
66 @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
69 @sic_e.refresh @gem_repo, true
72 new_gem = @sic_e.source_index.specification(@b2.full_name)
73 assert_equal @b2.full_name, new_gem.full_name