Skip to content

Commit

Permalink
test: Fix Sinatra Tests (open-telemetry#1253)
Browse files Browse the repository at this point in the history
* test: Fix Sinatra Tests

Sinatra 4.1 now includes a stricter host authorization check by default, which caused our tests to fail.

The host authorization is not enforced in development and test mode so this PR sets the Sinatra environment to run in `test` mode.

See: sinatra/sinatra#2053

fixes open-telemetry#1252

* squash: update appraisals

---------

Co-authored-by: Kayla Reopelle <[email protected]>
  • Loading branch information
arielvalentin and kaylareopelle authored Nov 19, 2024
1 parent acac4fd commit c28588e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 4 additions & 10 deletions instrumentation/sinatra/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
#
# SPDX-License-Identifier: Apache-2.0

appraise 'sinatra-4.x' do
gem 'sinatra', '~> 4.0'
end

appraise 'sinatra-3.x' do
gem 'sinatra', '~> 3.0'
end

appraise 'sinatra-2.x' do
gem 'sinatra', '~> 2.1'
%w[4.1 3.0 2.1].each do |version|
appraise "sinatra-#{version}" do
gem 'sinatra', "~> #{version}"
end
end

appraise 'sinatra-latest' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CustomError < StandardError; end

let(:app_one) do
Class.new(Sinatra::Application) do
set :raise_errors, false
get '/endpoint' do
'1'
end
Expand All @@ -41,6 +42,7 @@ class CustomError < StandardError; end

let(:app_two) do
Class.new(Sinatra::Application) do
set :raise_errors, false
get '/endpoint' do
'2'
end
Expand Down Expand Up @@ -165,7 +167,8 @@ class CustomError < StandardError; end
'http.method' => 'GET',
'http.route' => '/error',
'http.scheme' => 'http',
'http.target' => '/error'
'http.target' => '/error',
'http.status_code' => 500
)
_(exporter.finished_spans.flat_map(&:events).map(&:name)).must_equal(['exception'])
end
Expand Down
1 change: 1 addition & 0 deletions instrumentation/sinatra/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
ENV['APP_ENV'] = 'test'

require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down

0 comments on commit c28588e

Please sign in to comment.