Skip to content

Commit

Permalink
DEBUG-2334 Add integration_test helper (#3961)
Browse files Browse the repository at this point in the history
* DEBUG-2334 Add integration_test helper

DRY the logic to skip integration tests into a class-level helper

* rubocop

* rename helper to skip_unless_integration_testing_enabled

---------

Co-authored-by: Oleg Pudeyev <code@olegp.name>
  • Loading branch information
p-datadog and p authored Oct 1, 2024
1 parent 367153d commit a877d83
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spec/datadog/core/remote/transport/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'datadog/core/remote/transport/negotiation'

RSpec.describe Datadog::Core::Remote::Transport::HTTP do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

describe '.root' do
subject(:transport) { described_class.root(&client_options) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require 'spec/datadog/tracing/contrib/ethon/support/thread_helpers'

RSpec.describe 'Ethon integration tests' do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

context 'with Easy HTTP request' do
subject(:request) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'spec/datadog/tracing/contrib/ethon/support/thread_helpers'

RSpec.describe Datadog::Tracing::Contrib::Ethon do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

before(:context) do
# Ethon will lazily initialize LibCurl,
Expand Down
6 changes: 2 additions & 4 deletions spec/datadog/tracing/contrib/redis/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require 'datadog'

RSpec.describe 'Redis instrumentation test' do
skip_unless_integration_testing_enabled

let(:test_host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') }
let(:test_port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i }

Expand All @@ -20,10 +22,6 @@
Datadog.registry[:redis].reset_configuration!
end

before do
skip unless ENV['TEST_DATADOG_INTEGRATION']
end

RSpec::Matchers.define :be_a_redis_span do
match(notify_expectation_failures: true) do |span|
expect(span.name).to eq('redis.command')
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/contrib/redis/integration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
require 'datadog'

RSpec.describe 'Redis integration test' do
before do
skip unless ENV['TEST_DATADOG_INTEGRATION']
skip_unless_integration_testing_enabled

before do
use_real_tracer!

Datadog.configure do |c|
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/redis/miniapp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'datadog'

RSpec.describe 'Redis mini app test' do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

before do
Datadog.configure { |c| c.tracing.instrument :redis }
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

RSpec.describe 'Tracer integration tests' do
shared_context 'agent-based test' do
before do
skip unless ENV['TEST_DATADOG_INTEGRATION']
skip_unless_integration_testing_enabled

before do
# Ensure background Writer worker doesn't wait, making tests faster.
stub_const('Datadog::Tracing::Workers::AsyncTransport::DEFAULT_FLUSH_INTERVAL', 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'datadog/core/transport/http/adapters/net'

RSpec.describe 'Adapters::Net tracing integration tests' do
before { skip('Skipping test as ENV["TEST_DATADOG_INTEGRATION"] is not set') unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

subject(:adapter) { Datadog::Core::Transport::HTTP::Adapters::Net.new(agent_settings) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'datadog/core/transport/http/adapters/unix_socket'

RSpec.describe 'Adapters::UnixSocket integration tests' do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

subject(:adapter) { Datadog::Core::Transport::HTTP::Adapters::UnixSocket.new(**options) }

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/transport/http/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'datadog/tracing/transport/traces'

RSpec.describe 'Datadog::Tracing::Transport::HTTP integration tests' do
before { skip unless ENV['TEST_DATADOG_INTEGRATION'] }
skip_unless_integration_testing_enabled

describe 'HTTP#default' do
subject(:transport) { Datadog::Tracing::Transport::HTTP.default(&client_options) }
Expand Down
14 changes: 14 additions & 0 deletions spec/support/core_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ def supports_value_expectations?
false
end
end

module ClassMethods
def skip_unless_integration_testing_enabled
unless ENV['TEST_DATADOG_INTEGRATION']
before(:all) do
skip 'Set TEST_DATADOG_INTEGRATION=1 in environment to run this test'
end
end
end
end

def self.included(base)
base.extend ClassMethods
end
end
6 changes: 1 addition & 5 deletions spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ module RSpec
module Integration
def self.included(base)
base.class_exec do
before do
unless ENV['TEST_DATADOG_INTEGRATION']
skip('Integration tests can be enabled by setting the environment variable `TEST_DATADOG_INTEGRATION=1`')
end
end
skip_unless_integration_testing_enabled

include_context 'non-development execution environment'
end
Expand Down

0 comments on commit a877d83

Please sign in to comment.