Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Sep 25, 2024
1 parent 24eebe9 commit 14681aa
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def on_start(span, event, _id, payload)
key = payload[:key]
store = payload[:store]

mapping = MAPPING[event]
mapping = MAPPING.fetch(event)

span.service = configuration[:cache_service]
span.resource = mapping[:resource]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'
require 'datadog/tracing/contrib/active_record/events/instantiation'
require 'datadog/tracing/span_operation'

RSpec.describe Datadog::Tracing::Contrib::ActiveRecord::Events::Instantiation do
describe '.event_name' do
it 'returns the correct event name' do
expect(described_class.event_name).to eq('instantiation.active_record')
end
end

describe '.span_name' do
it 'returns the correct span name' do
expect(described_class.span_name).to eq('active_record.instantiation')
end
end

describe '.on_start' do
context 'when an error occurs' do
let(:span) { Datadog::Tracing::SpanOperation.new('fake') }

it 'logs the error' do
expect(Datadog.logger).to receive(:error).with(/key not found/)
expect(Datadog::Core::Telemetry::Logger).to receive(:report).with(a_kind_of(StandardError))

expect do
described_class.on_start(span, double, double, {})
end.not_to raise_error
end
end
end
end
34 changes: 34 additions & 0 deletions spec/datadog/tracing/contrib/active_record/events/sql_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'
require 'datadog/tracing/contrib/active_record/events/sql'
require 'datadog/tracing/span_operation'

require 'active_record'

RSpec.describe Datadog::Tracing::Contrib::ActiveRecord::Events::SQL do
describe '.event_name' do
it 'returns the correct event name' do
expect(described_class.event_name).to eq('sql.active_record')
end
end

describe '.span_name' do
it 'returns the correct span name' do
expect(described_class.span_name).to eq('active_record.sql')
end
end

describe '.on_start' do
context 'when an error occurs' do
let(:span) { Datadog::Tracing::SpanOperation.new('fake') }

it 'logs the error' do
expect(Datadog.logger).to receive(:error).with(/key not found/)
expect(Datadog::Core::Telemetry::Logger).to receive(:report).with(a_kind_of(StandardError))

expect do
described_class.on_start(span, double, double, {})
end.not_to raise_error
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'
require 'datadog/tracing/contrib/active_support/cache/events/cache'
require 'datadog/tracing/span_operation'

RSpec.describe Datadog::Tracing::Contrib::ActiveSupport::Cache::Events::Cache do
describe '.on_start' do
context 'when an error occurs' do
let(:span) { Datadog::Tracing::SpanOperation.new('fake') }

it 'logs the error' do
expect(Datadog.logger).to receive(:error).with(/key not found/)
expect(Datadog::Core::Telemetry::Logger).to receive(:report).with(a_kind_of(StandardError))

expect do
described_class.on_start(span, double, double, {})
end.not_to raise_error
end
end
end
end
24 changes: 24 additions & 0 deletions spec/datadog/tracing/contrib/redis/tags_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'
require 'datadog/tracing/contrib/redis/tags'

require 'datadog/tracing/span_operation'

RSpec.describe Datadog::Tracing::Contrib::Redis::Tags do
let(:client) { double('client') }
let(:span) { Datadog::Tracing::SpanOperation.new('fake') }
let(:raw_command) { 'SET key value' }

describe '.set_common_tags' do
context 'when an error occurs' do
it 'logs the error' do
allow(client).to receive(:host).and_raise(StandardError.new('Oops...'))
expect(Datadog.logger).to receive(:error).with('Oops...')
expect(Datadog::Core::Telemetry::Logger).to receive(:report).with(a_kind_of(StandardError))

expect do
described_class.set_common_tags(client, span, raw_command)
end.not_to raise_error
end
end
end
end

0 comments on commit 14681aa

Please sign in to comment.