Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] logging behavior for query hashes #759

Merged
merged 3 commits into from Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/excon/instrumentors/logging_instrumentor.rb
Expand Up @@ -28,7 +28,7 @@ def self.instrument(name, params = {})
info << "?"

if params[:query].is_a?(Hash)
info << params.to_a.map{ |key,value| "#{key}=#{value}" }.join('&')
info << params[:query].to_a.map { |key,value| "#{key}=#{value}" }.join('&')
else
info << params[:query]
end
Expand Down
34 changes: 32 additions & 2 deletions tests/instrumentors/logging_instrumentor_tests.rb
@@ -1,12 +1,13 @@
require 'logger'
require 'tempfile'

Shindo.tests('logging instrumentor') do
env_init

tests("connection logger").returns(true) do
Excon.stub({:method => :get}, {body: 'body', status: 200})

log_path = "/tmp/excon_#{Time.now.to_i}.txt"
log_path = Tempfile.create.path
logger = Logger.new(log_path)
# omit datetime to simplify test matcher
logger.formatter = proc do |severity, datetime, progname, msg|
Expand All @@ -19,13 +20,42 @@
logger: logger,
mock: true
)

response = connection.request(method: :get, path: '/logger')
File.readlines(log_path)[1..2] == [

File.readlines(log_path) == [
"request: http://127.0.0.1/logger\n",
"response: body\n"
]
end

tests("connection logger with query as hash").returns(true) do
criess marked this conversation as resolved.
Show resolved Hide resolved
Excon.stub({:method => :get}, {body: 'body', status: 200})

log_path = Tempfile.create.path
logger = Logger.new(log_path)
# omit datetime to simplify test matcher
logger.formatter = proc do |severity, datetime, progname, msg|
"#{msg}\n"
end

connection = Excon.new(
'http://127.0.0.1:9292',
instrumentor: Excon::LoggingInstrumentor,
logger: logger,
mock: true
)
response = connection.request(
method: :get,
path: '/logger',
query: {test: 'test'}
)
File.readlines(log_path) == [
"request: http://127.0.0.1/logger?test=test\n",
"response: body\n"
]
end

Excon.stubs.clear
env_restore
end