Skip to content

Commit

Permalink
Change name and made old name deprecated
Browse files Browse the repository at this point in the history
since helper's method have helper name as prefix

Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Jan 22, 2020
1 parent 0aab745 commit 3fe606b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/fluent/plugin_helper/http_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ def initialize(*)
@_http_server = nil
end

def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
logger.warn('this method is deprecated. Use #http_server_create_http_server instead')
http_server_create_http_server(title, addr: addr, port: port, logger: logger, default_app: default_app, proto: proto, tls_opts: tls_opts, &block)
end

# @param title [Symbol] the thread name. this value should be unique.
# @param addr [String] Listen address
# @param port [String] Listen port
# @param logger [Logger] logger used in this server
# @param default_app [Object] This method must have #call.
# @param proto [Symbol] :tls or :tcp
# @param tls_opts [Hash] options for TLS.
def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
def http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
unless block_given?
raise ArgumentError, 'BUG: callback not specified'
end
Expand Down
12 changes: 6 additions & 6 deletions test/plugin_helper/test_http_server_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr
sub_test_case 'Create a HTTP server' do
test 'monunt given path' do
on_driver do |driver|
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
s.post('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello post'] }
s.head('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello head'] }
Expand Down Expand Up @@ -214,7 +214,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr

test 'when path does not start with `/` or ends with `/`' do
on_driver do |driver|
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
s.get('example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
s.get('/example/hello2/') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
end
Expand All @@ -229,7 +229,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr

test 'when error raised' do
on_driver do |driver|
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
s.get('/example/hello') { raise 'error!' }
end

Expand All @@ -240,7 +240,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr

test 'when path is not found' do
on_driver do |driver|
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
end

Expand All @@ -251,7 +251,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr

test 'params and body' do
on_driver do |driver|
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
s.get('/example/hello') do |req|
assert_equal(req.query_string, nil)
assert_equal(req.body, nil)
Expand Down Expand Up @@ -390,7 +390,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr
end

stub(Fluent::PluginHelper::HttpServer::Server).new(anything) { server }
driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do
# nothing
end
driver.stop
Expand Down

0 comments on commit 3fe606b

Please sign in to comment.