fix datadog tests, both gem version compare and error type

error type has been wrongly tested sofar. This commit fixes it.
This commit is contained in:
HoneyryderChuck 2023-03-28 01:37:06 +01:00
parent 3bcf5bd5f6
commit 73f0d609b0

View File

@ -198,14 +198,14 @@ class DatadogTest < Minitest::Test
assert span.get_tag("http.method") == verb assert span.get_tag("http.method") == verb
assert span.get_tag("http.url") == uri.path assert span.get_tag("http.url") == uri.path
error_tag = if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.8.0" error_tag = if defined?(::DDTrace) && Gem::Version.new(::DDTrace::VERSION::STRING) >= Gem::Version.new("1.8.0")
"error.message" "error.message"
else else
"error.msg" "error.msg"
end end
if error if error
assert span.get_tag("error.type") == error assert span.get_tag("error.type") == "HTTPX::NativeResolveError"
assert !span.get_tag(error_tag).nil? assert !span.get_tag(error_tag).nil?
assert span.status == 1 assert span.status == 1
elsif response.status >= 400 elsif response.status >= 400
@ -241,7 +241,7 @@ class DatadogTest < Minitest::Test
assert span.get_metric("_dd1.sr.eausr") == sample_rate assert span.get_metric("_dd1.sr.eausr") == sample_rate
end end
if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0" if defined?(::DDTrace) && Gem::Version.new(::DDTrace::VERSION::STRING) >= Gem::Version.new("1.0.0")
def set_datadog(options = {}, &blk) def set_datadog(options = {}, &blk)
Datadog.configure do |c| Datadog.configure do |c|
@ -305,7 +305,7 @@ class DatadogTest < Minitest::Test
# Retrieves and sorts all spans in the current tracer instance. # Retrieves and sorts all spans in the current tracer instance.
# This method does not cache its results. # This method does not cache its results.
def fetch_spans def fetch_spans
spans = if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0" spans = if defined?(::DDTrace) && Gem::Version.new(::DDTrace::VERSION::STRING) >= Gem::Version.new("1.0.0")
(tracer.instance_variable_get(:@traces) || []).map(&:spans) (tracer.instance_variable_get(:@traces) || []).map(&:spans)
else else
tracer.instance_variable_get(:@spans) || [] tracer.instance_variable_get(:@spans) || []