2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/server'
7 attr_accessor :source_index
11 class TestGemServer < RubyGemTestCase
16 @a1 = quick_gem 'a', '1'
17 @a2 = quick_gem 'a', '2'
19 @server = Gem::Server.new Gem.dir, process_based_port, false
20 @req = WEBrick::HTTPRequest.new :Logger => nil
21 @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
25 data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
28 @server.Marshal @req, @res
30 assert_equal 200, @res.status, @res.body
31 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
32 assert_equal 'application/octet-stream', @res['content-type']
34 si = Gem::SourceIndex.new
37 assert_equal si, Marshal.load(@res.body)
41 data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
44 @server.Marshal @req, @res
46 assert_equal 200, @res.status, @res.body
47 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
48 assert_equal 'application/x-deflate', @res['content-type']
50 si = Gem::SourceIndex.new
53 assert_equal si, Marshal.load(Gem.inflate(@res.body))
57 data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
60 @server.latest_specs @req, @res
62 assert_equal 200, @res.status, @res.body
63 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
64 assert_equal 'application/octet-stream', @res['content-type']
65 assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
66 Marshal.load(@res.body)
69 def test_latest_specs_gz
70 data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
73 @server.latest_specs @req, @res
75 assert_equal 200, @res.status, @res.body
76 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
77 assert_equal 'application/x-gzip', @res['content-type']
78 assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
79 Marshal.load(Gem.gunzip(@res.body))
82 def test_quick_a_1_gemspec_rz
83 data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
86 @server.quick @req, @res
88 assert_equal 200, @res.status, @res.body
90 assert_equal 'application/x-deflate', @res['content-type']
92 spec = YAML.load Gem.inflate(@res.body)
93 assert_equal 'a', spec.name
94 assert_equal Gem::Version.new(1), spec.version
97 def test_quick_a_1_mswin32_gemspec_rz
98 a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
100 data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
103 @server.quick @req, @res
105 assert_equal 200, @res.status, @res.body
107 assert_equal 'application/x-deflate', @res['content-type']
109 spec = YAML.load Gem.inflate(@res.body)
110 assert_equal 'a', spec.name
111 assert_equal Gem::Version.new(1), spec.version
112 assert_equal Gem::Platform.local, spec.platform
115 def test_quick_common_substrings
116 ab1 = quick_gem 'ab', '1'
118 data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
121 @server.quick @req, @res
123 assert_equal 200, @res.status, @res.body
125 assert_equal 'application/x-deflate', @res['content-type']
127 spec = YAML.load Gem.inflate(@res.body)
128 assert_equal 'a', spec.name
129 assert_equal Gem::Version.new(1), spec.version
133 data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
136 @server.quick @req, @res
138 assert_equal 200, @res.status, @res.body
139 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
140 assert_equal 'text/plain', @res['content-type']
141 assert_equal "a-1\na-2", @res.body
144 def test_quick_index_rz
145 data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
148 @server.quick @req, @res
150 assert_equal 200, @res.status, @res.body
151 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
152 assert_equal 'application/x-deflate', @res['content-type']
153 assert_equal "a-1\na-2", Gem.inflate(@res.body)
156 def test_quick_latest_index
157 data = StringIO.new "GET /quick/latest_index HTTP/1.0\r\n\r\n"
160 @server.quick @req, @res
162 assert_equal 200, @res.status, @res.body
163 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
164 assert_equal 'text/plain', @res['content-type']
165 assert_equal 'a-2', @res.body
168 def test_quick_latest_index_rz
169 data = StringIO.new "GET /quick/latest_index.rz HTTP/1.0\r\n\r\n"
172 @server.quick @req, @res
174 assert_equal 200, @res.status, @res.body
175 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
176 assert_equal 'application/x-deflate', @res['content-type']
177 assert_equal 'a-2', Gem.inflate(@res.body)
180 def test_quick_missing
181 data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
184 @server.quick @req, @res
186 assert_equal 404, @res.status, @res.body
187 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
188 assert_equal 'text/plain', @res['content-type']
189 assert_equal 'No gems found matching "z" "9" nil', @res.body
190 assert_equal 404, @res.status
193 def test_quick_marshal_a_1_gemspec_rz
194 data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
197 @server.quick @req, @res
199 assert_equal 200, @res.status, @res.body
201 assert_equal 'application/x-deflate', @res['content-type']
203 spec = Marshal.load Gem.inflate(@res.body)
204 assert_equal 'a', spec.name
205 assert_equal Gem::Version.new(1), spec.version
208 def test_quick_marshal_a_1_mswin32_gemspec_rz
209 a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
211 data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
214 @server.quick @req, @res
216 assert_equal 200, @res.status, @res.body
218 assert_equal 'application/x-deflate', @res['content-type']
220 spec = Marshal.load Gem.inflate(@res.body)
221 assert_equal 'a', spec.name
222 assert_equal Gem::Version.new(1), spec.version
223 assert_equal Gem::Platform.local, spec.platform
228 data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
231 @server.root @req, @res
233 assert_equal 200, @res.status, @res.body
234 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
235 assert_equal 'text/html', @res['content-type']
239 data = StringIO.new "GET /specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
242 @server.specs @req, @res
244 assert_equal 200, @res.status, @res.body
245 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
246 assert_equal 'application/octet-stream', @res['content-type']
248 assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
249 ['a', Gem::Version.new(2), Gem::Platform::RUBY]],
250 Marshal.load(@res.body)
254 data = StringIO.new "GET /specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
257 @server.specs @req, @res
259 assert_equal 200, @res.status, @res.body
260 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
261 assert_equal 'application/x-gzip', @res['content-type']
263 assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
264 ['a', Gem::Version.new(2), Gem::Platform::RUBY]],
265 Marshal.load(Gem.gunzip(@res.body))
269 data = StringIO.new "GET /yaml.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
272 @server.yaml @req, @res
274 assert_equal 200, @res.status, @res.body
275 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
276 assert_equal 'text/plain', @res['content-type']
278 si = Gem::SourceIndex.new
279 si.add_specs @a1, @a2
281 assert_equal si, YAML.load(@res.body)
285 data = StringIO.new "GET /yaml.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
288 @server.yaml @req, @res
290 assert_equal 200, @res.status, @res.body
291 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
292 assert_equal 'application/x-deflate', @res['content-type']
294 si = Gem::SourceIndex.new
295 si.add_specs @a1, @a2
297 assert_equal si, YAML.load(Gem.inflate(@res.body))