Skip to content

Commit 74aa619

Browse files
committed
Test middleware_args_*
1 parent 5168831 commit 74aa619

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
require 'test_helper'
8+
9+
describe OpenTelemetry::Instrumentation::Rack::Instrumentation do
10+
let(:instrumentation_class) { OpenTelemetry::Instrumentation::Rack::Instrumentation }
11+
let(:instrumentation) { instrumentation_class.instance }
12+
let(:config) { {} }
13+
14+
before do
15+
skip unless ENV['BUNDLE_GEMFILE'].include?('dup')
16+
17+
# simulate a fresh install:
18+
instrumentation.instance_variable_set(:@installed, false)
19+
instrumentation.config.clear
20+
end
21+
22+
describe 'given default config options' do
23+
before do
24+
instrumentation.install(config)
25+
end
26+
27+
it 'is installed with default settings' do
28+
_(instrumentation).must_be :installed?
29+
_(instrumentation.config[:allowed_request_headers]).must_be_empty
30+
_(instrumentation.config[:allowed_response_headers]).must_be_empty
31+
_(instrumentation.config[:application]).must_be_nil
32+
_(instrumentation.config[:record_frontend_span]).must_equal false
33+
_(instrumentation.config[:untraced_endpoints]).must_be_empty
34+
_(instrumentation.config[:url_quantization]).must_be_nil
35+
_(instrumentation.config[:untraced_requests]).must_be_nil
36+
_(instrumentation.config[:response_propagators]).must_be_empty
37+
_(instrumentation.config[:use_rack_events]).must_equal true
38+
end
39+
end
40+
41+
describe 'when rack gem does not exist' do
42+
before do
43+
hide_const('Rack')
44+
instrumentation.install(config)
45+
end
46+
47+
it 'skips installation' do
48+
_(instrumentation).wont_be :installed?
49+
end
50+
end
51+
52+
describe '#middleware_args_old' do
53+
before do
54+
instrumentation.install(config)
55+
end
56+
57+
describe 'when rack events are configured' do
58+
let(:config) { Hash(use_rack_events: true) }
59+
60+
it 'instantiates a custom event handler' do
61+
args = instrumentation.middleware_args_dup
62+
_(args[0]).must_equal Rack::Events
63+
_(args[1][0]).must_be_instance_of OpenTelemetry::Instrumentation::Rack::Middlewares::Dup::EventHandler
64+
end
65+
end
66+
67+
describe 'when rack events are disabled' do
68+
let(:config) { Hash(use_rack_events: false) }
69+
70+
it 'instantiates a custom middleware' do
71+
args = instrumentation.middleware_args_dup
72+
_(args).must_equal [OpenTelemetry::Instrumentation::Rack::Middlewares::Dup::TracerMiddleware]
73+
end
74+
end
75+
end
76+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
require 'test_helper'
8+
9+
describe OpenTelemetry::Instrumentation::Rack::Instrumentation do
10+
let(:instrumentation_class) { OpenTelemetry::Instrumentation::Rack::Instrumentation }
11+
let(:instrumentation) { instrumentation_class.instance }
12+
let(:config) { {} }
13+
14+
before do
15+
skip unless ENV['BUNDLE_GEMFILE'].include?('http')
16+
17+
# simulate a fresh install:
18+
instrumentation.instance_variable_set(:@installed, false)
19+
instrumentation.config.clear
20+
end
21+
22+
describe 'given default config options' do
23+
before do
24+
instrumentation.install(config)
25+
end
26+
27+
it 'is installed with default settings' do
28+
_(instrumentation).must_be :installed?
29+
_(instrumentation.config[:allowed_request_headers]).must_be_empty
30+
_(instrumentation.config[:allowed_response_headers]).must_be_empty
31+
_(instrumentation.config[:application]).must_be_nil
32+
_(instrumentation.config[:record_frontend_span]).must_equal false
33+
_(instrumentation.config[:untraced_endpoints]).must_be_empty
34+
_(instrumentation.config[:url_quantization]).must_be_nil
35+
_(instrumentation.config[:untraced_requests]).must_be_nil
36+
_(instrumentation.config[:response_propagators]).must_be_empty
37+
_(instrumentation.config[:use_rack_events]).must_equal true
38+
end
39+
end
40+
41+
describe 'when rack gem does not exist' do
42+
before do
43+
hide_const('Rack')
44+
instrumentation.install(config)
45+
end
46+
47+
it 'skips installation' do
48+
_(instrumentation).wont_be :installed?
49+
end
50+
end
51+
52+
describe '#middleware_args_old' do
53+
before do
54+
instrumentation.install(config)
55+
end
56+
57+
describe 'when rack events are configured' do
58+
let(:config) { Hash(use_rack_events: true) }
59+
60+
it 'instantiates a custom event handler' do
61+
args = instrumentation.middleware_args_stable
62+
_(args[0]).must_equal Rack::Events
63+
_(args[1][0]).must_be_instance_of OpenTelemetry::Instrumentation::Rack::Middlewares::Stable::EventHandler
64+
end
65+
end
66+
67+
describe 'when rack events are disabled' do
68+
let(:config) { Hash(use_rack_events: false) }
69+
70+
it 'instantiates a custom middleware' do
71+
args = instrumentation.middleware_args_stable
72+
_(args).must_equal [OpenTelemetry::Instrumentation::Rack::Middlewares::Stable::TracerMiddleware]
73+
end
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)