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
43 assert_equal [], sic_e.source_index.map { |n,| n }
46 assert sic_e.refresh(@gem_repo, false)
49 assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
52 sic_e.refresh @gem_repo, true
55 assert_equal [a1_name, a2_name], sic_e.source_index.map { |n,| n }.sort
58 def test_refresh_bad_uri
59 assert_raise URI::BadURIError do
60 @sic_e.refresh 'gems.example.com', true
64 def test_refresh_update
65 si = Gem::SourceIndex.new
68 @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
71 @sic_e.refresh @gem_repo, true
74 new_gem = @sic_e.source_index.specification(@b2.full_name)
75 assert_equal @b2.full_name, new_gem.full_name