Sha256: 1f6e3ec3d042edff5d8a78b1baac3c26b665876a11bf0ca2c1e632e073dfd075

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'

def assert_proxy(host, port, send, recv)
  sock = TCPSocket.new(host, port)
  sock.write(send)
  assert_equal recv, sock.read
  sock.close
end

class ProxymachineTest < Test::Unit::TestCase
  should "handle simple routing" do
    assert_proxy('localhost', 9990, 'a', '9980:a')
    assert_proxy('localhost', 9990, 'b', '9981:b')
  end

  should "handle connection closing" do
    sock = TCPSocket.new('localhost', 9990)
    sock.write('xxx')
    assert_equal nil, sock.read(1)
    sock.close
  end

  should "handle rewrite routing" do
    assert_proxy('localhost', 9990, 'c', '9980:ccc')
  end

  should "handle rewrite closing" do
    assert_proxy('localhost', 9990, 'd', 'ddd')
  end

  should "handle data plus reply" do
    assert_proxy('localhost', 9990, 'g', 'g3-9980:g2')
  end

  should "handle noop" do
    sock = TCPSocket.new('localhost', 9990)
    sock.write('e' * 2048)
    sock.flush
    sock.write('f')
    assert_equal '9980:' + 'e' * 2048 + 'f', sock.read
    sock.close
  end

  should "execute a callback" do
    assert_proxy('localhost', 9990, 'h', '9980:h:callback')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fizx-proxymachine-1.3.0 test/proxymachine_test.rb
fizx-proxymachine-1.2.0 test/proxymachine_test.rb