root/lang/ruby/ssb/trunk/test/ssb_test.rb @ 2212

Revision 2212, 1.7 kB (checked in by coji, 6 years ago)

lang/ruby/ssb: add mock_csv, introduce new testing tool dust. http://dust.rubyforge.org/

  • Property svn:mime-type set to text/x-ruby; charset=utf-8
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date Author Rev URL
Line 
1require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
3unit_tests do
4  def setup
5    @savedir = Dir.pwd
6    Dir.chdir 'public_html'
7    @mock_server = MockServer.new
8  end
9
10  def teardown
11    @mock_server.shutdown
12    Dir.chdir @savedir
13  end
14
15  # launch ssb process via pipe
16  def kick_ssb(method, query_string, postparams = nil)
17    return ''
18    # CGI Parameters
19    ENV['SERVER_NAME'] = 'localhost'
20    ENV['SCRIPT_NAME'] = '/index.rbx'
21    ENV['REQUEST_METHOD'] = method
22    ENV['QUERY_STRING']   = query_string
23    if postparams.nil?
24      ENV['CONTENT_LENGTH'] = '0'
25    else
26      ENV['CONTENT_LENGTH'] = postparams.size.to_s
27    end
28    open_type = {
29      'GET'  => 'r',
30      'POST' => 'r+',
31    }
32
33    ret = ''
34    begin
35      IO.popen('ruby -Ku index.rbx', open_type[method]) do |io|
36        if method == 'POST'
37          io.puts postparams unless postparams.nil?
38          io.close_write
39        end
40        while read = io.gets
41          ret.concat(read)
42        end
43      end
44    rescue =>e
45      ret = e.backtrace.to_s
46    end
47    ret
48  end
49
50  test 'ssb get local' do
51    ret = kick_ssb('GET', "q=#{@mock_server.uri}&uid=NULLGWDOCOMO")
52    assert_match(/It works by GET/, ret)
53  end
54
55  test 'ssb get invalidhost' do
56    # noname is invalid hostname
57    ret = kick_ssb('GET', 'q=noname')
58    assert_match(/getaddrinfo: nodename nor servname provided/, ret)
59  end
60
61  test 'ssb post local' do
62    ret = kick_ssb('POST', '', "q=#{@mock_server.uri}&param=test&uid=NULLGWDOCOMO")
63    assert_match(/It works by POST/, ret)
64  end
65
66  test 'ssb_post_invalidhost' do
67    # noname is invalid hostname
68    ret = kick_ssb('POST', '', 'q=noname&param=test&uid=NULLGWDOCOMO')
69    assert_match(/getaddrinfo: nodename nor servname provided/, ret)
70  end
71end
Note: See TracBrowser for help on using the browser.