~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_server.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
 
3
require 'rubygems/server'
 
4
require 'stringio'
 
5
 
 
6
class Gem::Server
 
7
  attr_accessor :source_index
 
8
  attr_reader :server
 
9
end
 
10
 
 
11
class TestGemServer < RubyGemTestCase
 
12
 
 
13
  def setup
 
14
    super
 
15
 
 
16
    @a1 = quick_gem 'a', '1'
 
17
 
 
18
    @server = Gem::Server.new Gem.dir, 8809, false
 
19
    @req = WEBrick::HTTPRequest.new :Logger => nil
 
20
    @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
 
21
  end
 
22
 
 
23
  def test_quick_index
 
24
    data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
 
25
    @req.parse data
 
26
 
 
27
    @server.quick @req, @res
 
28
 
 
29
    assert_equal 200, @res.status, @res.body
 
30
    assert_match %r| \d\d:\d\d:\d\d |, @res['date']
 
31
    assert_equal 'text/plain', @res['content-type']
 
32
    assert_equal "a-1", @res.body
 
33
  end
 
34
 
 
35
  def test_quick_index_rz
 
36
    data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
 
37
    @req.parse data
 
38
 
 
39
    @server.quick @req, @res
 
40
 
 
41
    assert_equal 200, @res.status, @res.body
 
42
    assert_match %r| \d\d:\d\d:\d\d |, @res['date']
 
43
    assert_equal 'text/plain', @res['content-type']
 
44
    assert_equal "a-1", Zlib::Inflate.inflate(@res.body)
 
45
  end
 
46
 
 
47
  def test_quick_a_1_gemspec_rz
 
48
    data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
 
49
    @req.parse data
 
50
 
 
51
    @server.quick @req, @res
 
52
 
 
53
    assert_equal 200, @res.status, @res.body
 
54
    assert @res['date']
 
55
    assert_equal 'text/plain', @res['content-type']
 
56
    yaml = Zlib::Inflate.inflate(@res.body)
 
57
    assert_match %r|Gem::Specification|, yaml
 
58
    assert_match %r|name: a|, yaml
 
59
    assert_match %r|version: "1"|, yaml
 
60
  end
 
61
 
 
62
  def test_quick_a_1_mswin32_gemspec_rz
 
63
    a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
 
64
    si = Gem::SourceIndex.new @a1.full_name => @a1, a1_p.full_name => a1_p
 
65
    @server.source_index = si
 
66
 
 
67
    data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
 
68
    @req.parse data
 
69
 
 
70
    @server.quick @req, @res
 
71
 
 
72
    assert_equal 200, @res.status, @res.body
 
73
    assert @res['date']
 
74
    assert_equal 'text/plain', @res['content-type']
 
75
    yaml = Zlib::Inflate.inflate(@res.body)
 
76
    assert_match %r|Gem::Specification|, yaml
 
77
    assert_match %r|name: a|, yaml
 
78
    assert_match %r|version: "1"|, yaml
 
79
  end
 
80
 
 
81
  def test_quick_common_substrings
 
82
    ab1 = quick_gem 'ab', '1'
 
83
    si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1
 
84
    @server.source_index = si
 
85
 
 
86
    data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
 
87
    @req.parse data
 
88
 
 
89
    @server.quick @req, @res
 
90
 
 
91
    assert_equal 200, @res.status, @res.body
 
92
    assert @res['date']
 
93
    assert_equal 'text/plain', @res['content-type']
 
94
    yaml = Zlib::Inflate.inflate @res.body
 
95
    assert_match %r|Gem::Specification|, yaml
 
96
    assert_match %r|name: a$|, yaml
 
97
    assert_match %r|version: "1"|, yaml
 
98
  end
 
99
 
 
100
  def test_quick_z_9_gemspec_rz
 
101
    data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
 
102
    @req.parse data
 
103
 
 
104
    @server.quick @req, @res
 
105
 
 
106
    assert_equal 404, @res.status, @res.body
 
107
    assert_match %r| \d\d:\d\d:\d\d |, @res['date']
 
108
    assert_equal 'text/plain', @res['content-type']
 
109
    assert_equal 'No gems found matching "z" "9" nil', @res.body
 
110
    assert_equal 404, @res.status
 
111
  end
 
112
 
 
113
end
 
114