forked from excon/excon
/
logging_instrumentor_tests.rb
61 lines (51 loc) · 1.47 KB
/
logging_instrumentor_tests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 = 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')
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
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