bane 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +49 -0
  3. data/LICENSE +1 -1
  4. data/README.md +41 -31
  5. data/TODO +15 -10
  6. data/bin/bane +8 -11
  7. data/lib/bane/arguments_parser.rb +75 -0
  8. data/lib/bane/behavior_maker.rb +41 -0
  9. data/lib/bane/behaviors/responders/close_after_pause.rb +23 -0
  10. data/lib/bane/behaviors/responders/close_immediately.rb +16 -0
  11. data/lib/bane/behaviors/responders/deluge_response.rb +29 -0
  12. data/lib/bane/behaviors/responders/echo_response.rb +18 -0
  13. data/lib/bane/behaviors/responders/exported.rb +11 -0
  14. data/lib/bane/behaviors/responders/fixed_response.rb +27 -0
  15. data/lib/bane/behaviors/responders/for_each_line.rb +20 -0
  16. data/lib/bane/behaviors/responders/http_refuse_all_credentials.rb +33 -0
  17. data/lib/bane/behaviors/responders/never_respond.rb +29 -0
  18. data/lib/bane/behaviors/responders/newline_response.rb +20 -0
  19. data/lib/bane/behaviors/responders/random_response.rb +26 -0
  20. data/lib/bane/behaviors/responders/slow_response.rb +34 -0
  21. data/lib/bane/behaviors/servers/exported.rb +20 -0
  22. data/lib/bane/behaviors/servers/responder_server.rb +52 -0
  23. data/lib/bane/behaviors/servers/timeout_in_listen_queue.rb +53 -0
  24. data/lib/bane/command_line_configuration.rb +41 -0
  25. data/lib/bane/extensions.rb +9 -0
  26. data/lib/bane/launcher.rb +9 -8
  27. data/lib/bane/naive_http_response.rb +2 -0
  28. data/lib/bane/version.rb +5 -0
  29. data/lib/bane.rb +21 -6
  30. metadata +104 -102
  31. data/Rakefile +0 -60
  32. data/examples/simple_port_and_class_as_constant.rb +0 -9
  33. data/examples/simple_port_and_class_as_string.rb +0 -7
  34. data/examples/specify_behavior_options.rb +0 -16
  35. data/examples/specify_ports.rb +0 -15
  36. data/lib/bane/behaviors.rb +0 -151
  37. data/lib/bane/compatibility.rb +0 -36
  38. data/lib/bane/configuration.rb +0 -50
  39. data/lib/bane/configuration_parser.rb +0 -74
  40. data/lib/bane/delegating_gserver.rb +0 -42
  41. data/lib/bane/service_registry.rb +0 -17
  42. data/test/bane/behaviors_test.rb +0 -137
  43. data/test/bane/configuration_parser_test.rb +0 -124
  44. data/test/bane/configuration_test.rb +0 -52
  45. data/test/bane/delegating_gserver_test.rb +0 -56
  46. data/test/bane/integration_test.rb +0 -67
  47. data/test/bane/launcher_test.rb +0 -16
  48. data/test/bane/naive_http_response_test.rb +0 -69
  49. data/test/bane/service_registry_test.rb +0 -20
  50. data/test/test_helper.rb +0 -9
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'mocha'
3
-
4
- class DelegatingGserverTest < Test::Unit::TestCase
5
- include Bane
6
-
7
- IRRELEVANT_IO_STREAM = nil
8
- IRRELEVANT_OPTIONS = {}
9
-
10
- def test_serve_passes_a_hash_of_options_even_if_not_initialized_with_options
11
- behavior = mock()
12
- server = DelegatingGServer.new(IRRELEVANT_PORT, behavior)
13
-
14
- behavior.expects(:serve).with(anything(), is_a(Hash))
15
-
16
- server.serve(IRRELEVANT_IO_STREAM)
17
- end
18
-
19
- def test_serve_passes_constructor_options_to_behaviors_serve_method
20
- behavior = mock()
21
-
22
- initialized_options = {:expected => :options}
23
- server = DelegatingGServer.new(IRRELEVANT_PORT, behavior, initialized_options)
24
-
25
- behavior.expects(:serve).with(anything(), equals(initialized_options))
26
-
27
- server.serve(IRRELEVANT_IO_STREAM)
28
- end
29
-
30
- def test_connection_log_messages_use_short_behavior_name_to_shorten_log_messages
31
- [:connecting, :disconnecting].each do |method|
32
- assert_log_message_uses_short_behavior_name_for(method) do |server|
33
- server.send(method, stub_everything(:peeraddr => [127, 0, 0, 1]))
34
- end
35
- end
36
- end
37
-
38
- def test_start_stop_log_messages_use_short_behavior_name_to_shorten_log_messages
39
- [:starting, :stopping].each do |method|
40
- assert_log_message_uses_short_behavior_name_for(method) do |server|
41
- server.send(method)
42
- end
43
- end
44
- end
45
-
46
- def assert_log_message_uses_short_behavior_name_for(method)
47
- logger = StringIO.new
48
- server = DelegatingGServer.new(IRRELEVANT_PORT, Bane::Behaviors::CloseImmediately.new, IRRELEVANT_OPTIONS, logger)
49
-
50
- yield server
51
-
52
- assert_match /CloseImmediately/, logger.string, "Log for #{method} should contain class short name"
53
- assert_no_match /Behaviors::CloseImmediately/, logger.string, "Log for #{method} should not contain expanded module name"
54
- end
55
-
56
- end
@@ -1,67 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'net/telnet'
3
- require 'open-uri'
4
-
5
- class BaneIntegrationTest < Test::Unit::TestCase
6
-
7
- TEST_PORT = 4000
8
-
9
- def test_uses_specified_port_and_server
10
- run_server_with(TEST_PORT, "FixedResponse") do
11
- telnet_to TEST_PORT do |response|
12
- assert !response.empty?, "Should have had a non-empty response"
13
- end
14
- end
15
- end
16
-
17
- def test_uses_behavior_options
18
- expected_message = "Expected test message"
19
- options = {TEST_PORT => {:behavior => Bane::Behaviors::FixedResponse,
20
- :message => expected_message}}
21
-
22
- run_server_with(options) do
23
- telnet_to TEST_PORT do |response|
24
- assert_equal expected_message, response, "Wrong response from server"
25
- end
26
- end
27
- end
28
-
29
- def test_serves_http_requests
30
- run_server_with(TEST_PORT, "HttpRefuseAllCredentials") do
31
- begin
32
- open("http://localhost:#{TEST_PORT}/some/url").read
33
- flunk "Should have refused access"
34
- rescue OpenURI::HTTPError => e
35
- assert_match /401/, e.message
36
- end
37
- end
38
-
39
- end
40
-
41
- private
42
-
43
- def run_server_with(*options)
44
- begin
45
- launcher = Bane::Launcher.new(Configuration(*options), quiet_logger)
46
- launcher.start
47
- yield
48
- ensure
49
- launcher.stop if launcher
50
- end
51
- end
52
-
53
- def quiet_logger
54
- StringIO.new
55
- end
56
-
57
- def telnet_to(port)
58
- begin
59
- telnet = Net::Telnet::new("Host" => "localhost",
60
- "Port" => port,
61
- "Timeout" => 5)
62
- yield telnet.read
63
- ensure
64
- telnet.close
65
- end
66
- end
67
- end
@@ -1,16 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'mocha'
3
-
4
- class LauncherTest < Test::Unit::TestCase
5
-
6
- include Bane
7
-
8
- def test_start_delegates_to_configuration
9
- configuration = mock()
10
- logger = stub()
11
- launcher = Launcher.new(configuration, logger)
12
-
13
- configuration.expects(:start).with(equals(logger))
14
- launcher.start
15
- end
16
- end
@@ -1,69 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class NaiveHttpResponseTest < Test::Unit::TestCase
4
-
5
- IRRELEVANT_RESPONSE_CODE = "999"
6
- IRRELEVANT_RESPONSE_DESCRIPTION = "Irrelevant description"
7
- IRRELEVANT_CONTENT_TYPE = "irrelevant content type"
8
- IRRELEVANT_BODY = "irrelevant body"
9
-
10
- def test_should_send_http_format_string
11
- response = response_for("200", "OK", IRRELEVANT_CONTENT_TYPE, IRRELEVANT_BODY)
12
- assert_equal "HTTP/1.1 200 OK\r\n", response.lines.first, "First line should be HTTP status"
13
- end
14
-
15
- def test_should_include_date
16
- assert_match /Date: .*/, any_response, 'Should have included a Date header'
17
- end
18
-
19
- def test_should_set_content_type
20
- response = response_for(IRRELEVANT_RESPONSE_CODE,
21
- IRRELEVANT_RESPONSE_DESCRIPTION,
22
- "text/xml",
23
- IRRELEVANT_BODY)
24
- assert_match /Content-Type: text\/xml/, response, 'Should have included content type'
25
- end
26
-
27
- def test_should_set_content_length_as_length_of_body_in_bytes
28
- message = "Hello, there!"
29
- response = response_for(IRRELEVANT_RESPONSE_CODE,
30
- IRRELEVANT_RESPONSE_DESCRIPTION,
31
- IRRELEVANT_CONTENT_TYPE,
32
- message)
33
-
34
- assert_match /Content-Length: #{message.length}/, response, 'Should have included content length'
35
- end
36
-
37
- def test_should_include_newline_between_headers_and_body
38
- message = "This is some body content."
39
- response = response_for(IRRELEVANT_RESPONSE_CODE,
40
- IRRELEVANT_RESPONSE_DESCRIPTION,
41
- IRRELEVANT_CONTENT_TYPE,
42
- message)
43
-
44
- response_lines = response.lines.to_a
45
- index_of_body_start = response_lines.index(message)
46
- line_before_body = response_lines[index_of_body_start - 1]
47
- assert line_before_body.strip.empty?, "Should have had blank line before the body"
48
- end
49
-
50
- def test_should_include_the_body_at_the_end_of_the_response
51
- message = "This is some body content."
52
- response = response_for(IRRELEVANT_RESPONSE_CODE,
53
- IRRELEVANT_RESPONSE_DESCRIPTION,
54
- IRRELEVANT_CONTENT_TYPE,
55
- message)
56
- assert_match /#{message}$/, response, "Should have ended the response with the body content"
57
- end
58
-
59
- private
60
-
61
- def response_for(response_code, response_description, content_type, body)
62
- NaiveHttpResponse.new(response_code, response_description, content_type, body).to_s
63
- end
64
-
65
- def any_response
66
- response_for(IRRELEVANT_RESPONSE_CODE, IRRELEVANT_RESPONSE_DESCRIPTION, IRRELEVANT_CONTENT_TYPE, IRRELEVANT_BODY)
67
- end
68
-
69
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class ServiceRegistryTest < Test::Unit::TestCase
4
-
5
- include Bane
6
-
7
- def test_should_add_and_remove_behaviors
8
- fake = fake_behavior
9
-
10
- ServiceRegistry.register(fake)
11
- assert ServiceRegistry.all_servers.include?(fake), "Should have added the new behavior"
12
-
13
- ServiceRegistry.unregister(fake)
14
- assert !(ServiceRegistry.all_servers.include?(fake)), "Should have removed the new behavior"
15
- end
16
-
17
- def fake_behavior
18
- Class.new
19
- end
20
- end
data/test/test_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'stringio'
4
-
5
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
6
- require 'bane'
7
-
8
-
9
- IRRELEVANT_PORT = 4001