Skip to content

Commit

Permalink
serverless tests: skip unless Ruby 3.2+
Browse files Browse the repository at this point in the history
the serverless handler is only used with Ruby v3.2+, so only test with
Ruby v3.2+
  • Loading branch information
fallwith committed Aug 16, 2024
1 parent af52a76 commit 839bb1b
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions test/new_relic/agent/serverless_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,23 @@ class ServerlessHandlerTest < Minitest::Test
}

def setup
skip 'Serverless usage is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

config_hash = {:'serverless_mode.enabled' => true}
@test_config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
NewRelic::Agent.config.add_config_for_testing(@test_config, true)
handler.send(:reset!)
end

def teardown
skip unless defined?(@test_config)

NewRelic::Agent.config.remove_config(@test_config)
end

# integration style

def test_the_complete_handoff_from_the_nr_lambda_layer
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

context = testing_context
output = with_output do
result = handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
Expand All @@ -104,8 +106,6 @@ def test_the_complete_handoff_from_the_nr_lambda_layer
end

def test_rescued_errors_are_noticed
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

output = with_output do
assert_raises RuntimeError do
handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
Expand All @@ -123,8 +123,6 @@ def test_rescued_errors_are_noticed
end

def test_log_events_are_reported
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

output = with_output do
handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
event: {simulate_logging: true},
Expand All @@ -135,8 +133,6 @@ def test_log_events_are_reported
end

def test_customer_function_lives_within_a_namespace
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

context = testing_context
output = with_output do
result = handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
Expand All @@ -153,8 +149,6 @@ def test_customer_function_lives_within_a_namespace
end

def test_agent_attributes_are_present
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

context = testing_context
output = with_output do
result = handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
Expand All @@ -171,8 +165,6 @@ def test_agent_attributes_are_present
end

def test_metric_data_adheres_to_the_agent_specs
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

output = with_output do
handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
event: {},
Expand All @@ -199,8 +191,6 @@ def test_metric_data_adheres_to_the_agent_specs
end

def test_support_for_payload_format_v1
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

NewRelic::Agent::ServerlessHandler.stub_const(:PAYLOAD_VERSION, 1) do
output = with_output do
result = handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
Expand All @@ -218,8 +208,6 @@ def test_support_for_payload_format_v1
end

def test_distributed_tracing_for_api_gateway_v1
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

event = {'version' => '1.0',
'httpMethod' => 'POST',
'headers' => {NewRelic::NEWRELIC_KEY => {
Expand All @@ -230,8 +218,6 @@ def test_distributed_tracing_for_api_gateway_v1
end

def test_distributed_tracing_for_api_gateway_v2
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

event = {'version' => '2.0',
'httpMethod' => 'POST',
'requestContext' => {'http' => {NewRelic::NEWRELIC_KEY => {
Expand All @@ -242,8 +228,6 @@ def test_distributed_tracing_for_api_gateway_v2
end

def test_reports_web_attributes_for_api_gateway_v1
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

event = {'version' => '1.0',
'resource' => '/RG35XXSP',
'path' => '/default/RG35XXSP',
Expand All @@ -266,8 +250,6 @@ def test_reports_web_attributes_for_api_gateway_v1
end

def test_reports_web_attributes_for_api_gateway_v2
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

event = {'version' => '2.0',
'headers' => {'X-Forwarded-Port' => 443},
'queryStringParameters' => {'param1': 'value1', 'param2': 'value2'},
Expand All @@ -279,8 +261,6 @@ def test_reports_web_attributes_for_api_gateway_v2

EVENT_SOURCES.each do |type, info|
define_method(:"test_event_type_#{type}") do
skip 'This serverless test is limited to Ruby v3.2+' unless ruby_version_float >= 3.2

output = with_output do
handler.invoke_lambda_function_with_new_relic(method_name: :customer_lambda_function,
event: info['event'],
Expand Down

0 comments on commit 839bb1b

Please sign in to comment.