-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Datadog::Contrib specs related to integration configuration.
- Loading branch information
Showing
6 changed files
with
291 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace' | ||
|
||
RSpec.describe Datadog::Contrib::Configurable do | ||
describe 'implemented' do | ||
subject(:configurable_class) do | ||
Class.new.tap do |klass| | ||
klass.send(:include, described_class) | ||
end | ||
end | ||
|
||
describe 'instance behavior' do | ||
subject(:configurable_object) { configurable_class.new } | ||
|
||
describe '#default_configuration' do | ||
subject(:configuration) { configurable_object.default_configuration } | ||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Configuration::Settings) } | ||
end | ||
|
||
describe '#reset_configuration!' do | ||
subject(:reset) { configurable_object.reset_configuration! } | ||
|
||
context 'when a configuration has been added' do | ||
before(:each) { configurable_object.configure(:foo, service_name: 'bar') } | ||
|
||
it do | ||
expect { reset }.to change { configurable_object.configurations.keys } | ||
.from([:default, :foo]) | ||
.to([:default]) | ||
end | ||
end | ||
end | ||
|
||
describe '#configuration' do | ||
context 'when no name is provided' do | ||
subject(:configuration) { configurable_object.configuration } | ||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Configuration::Settings) } | ||
it { is_expected.to be(configurable_object.configurations[:default]) } | ||
end | ||
|
||
context 'when a name is provided' do | ||
subject(:configuration) { configurable_object.configuration(name) } | ||
let(:name) { :foo } | ||
|
||
context 'and the configuration exists' do | ||
before(:each) { configurable_object.configure(:foo, service_name: 'bar') } | ||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Configuration::Settings) } | ||
it { is_expected.to be(configurable_object.configurations[:foo]) } | ||
end | ||
|
||
context 'but the configuration doesn\'t exist' do | ||
it { is_expected.to be nil } | ||
end | ||
end | ||
end | ||
|
||
describe '#configurations' do | ||
subject(:configurations) { configurable_object.configurations } | ||
|
||
context 'when nothing has been explicitly configured' do | ||
it { is_expected.to include(default: a_kind_of(Datadog::Contrib::Configuration::Settings)) } | ||
end | ||
|
||
context 'when a configuration has been added' do | ||
before(:each) { configurable_object.configure(:foo, service_name: 'bar') } | ||
|
||
it do | ||
is_expected.to include( | ||
default: a_kind_of(Datadog::Contrib::Configuration::Settings), | ||
foo: a_kind_of(Datadog::Contrib::Configuration::Settings) | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe '#configure' do | ||
context 'when provided a name' do | ||
subject(:configure) { configurable_object.configure(name, service_name: 'bar') } | ||
let(:name) { :foo } | ||
|
||
context 'that matches an existing configuration' do | ||
before(:each) { configurable_object.configure(name, service_name: 'baz') } | ||
|
||
it do | ||
expect { configure }.to change { configurable_object.configuration(name).service_name } | ||
.from('baz') | ||
.to('bar') | ||
end | ||
end | ||
|
||
context 'that does not match any configuration' do | ||
it do | ||
expect { configure }.to change { configurable_object.configuration(name) } | ||
.from(nil) | ||
.to(a_kind_of(Datadog::Contrib::Configuration::Settings)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace' | ||
|
||
RSpec.describe Datadog::Contrib::Integration do | ||
describe 'implemented' do | ||
subject(:integration_class) do | ||
Class.new.tap do |klass| | ||
klass.send(:include, described_class) | ||
end | ||
end | ||
|
||
describe 'instance behavior' do | ||
subject(:integration_object) { integration_class.new(name) } | ||
let(:name) { :foo } | ||
|
||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Configurable) } | ||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Patchable) } | ||
it { is_expected.to be_a_kind_of(Datadog::Contrib::Registerable) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace' | ||
|
||
RSpec.describe Datadog::Contrib::Patchable do | ||
describe 'implemented' do | ||
subject(:patchable_class) do | ||
Class.new.tap do |klass| | ||
klass.send(:include, described_class) | ||
end | ||
end | ||
|
||
describe 'class behavior' do | ||
describe '#compatible?' do | ||
subject(:compatible) { patchable_class.compatible? } | ||
let(:expected_compatibility) { RUBY_VERSION >= '1.9.3' ? true : false } | ||
it { is_expected.to be expected_compatibility } | ||
end | ||
end | ||
|
||
describe 'instance behavior' do | ||
subject(:patchable_object) { patchable_class.new } | ||
|
||
describe '#patcher' do | ||
subject(:patcher) { patchable_object.patcher } | ||
it { is_expected.to be nil } | ||
end | ||
|
||
describe '#patch' do | ||
subject(:patch) { patchable_object.patch } | ||
|
||
context 'when the patchable object' do | ||
context 'is compatible' do | ||
before(:each) { allow(patchable_class).to receive(:compatible?).and_return(true) } | ||
|
||
context 'and the patcher is defined' do | ||
let(:patcher) { double('patcher') } | ||
before(:each) { allow(patchable_object).to receive(:patcher).and_return(patcher) } | ||
|
||
it 'applies the patch' do | ||
expect(patcher).to receive(:patch) | ||
patch | ||
end | ||
end | ||
|
||
context 'and the patcher is nil' do | ||
it 'does not applies the patch' do | ||
is_expected.to be nil | ||
end | ||
end | ||
end | ||
|
||
context 'is not compatible' do | ||
it 'does not applies the patch' do | ||
is_expected.to be nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace' | ||
require 'ddtrace/contrib/patcher' | ||
|
||
RSpec.describe Datadog::Contrib::Patcher do | ||
describe 'implemented' do | ||
subject(:patcher_class) do | ||
Class.new.tap do |klass| | ||
klass.send(:include, described_class) | ||
end | ||
end | ||
|
||
describe 'class behavior' do | ||
describe '#patch' do | ||
subject(:patch) { patcher_class.patch } | ||
it { expect { patch }.to raise_error(NotImplementedError) } | ||
end | ||
end | ||
|
||
describe 'instance behavior' do | ||
subject(:patcher_object) { patcher_class.new } | ||
|
||
it { is_expected.to be_a_kind_of(Datadog::Patcher) } | ||
|
||
describe '#patch' do | ||
subject(:patch) { patcher_object.patch } | ||
it { expect { patch }.to raise_error(NotImplementedError) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace' | ||
|
||
RSpec.describe Datadog::Contrib::Registerable do | ||
describe 'implemented' do | ||
subject(:registerable_class) do | ||
Class.new.tap do |klass| | ||
klass.send(:include, described_class) | ||
end | ||
end | ||
|
||
describe 'class behavior' do | ||
describe '#register_as' do | ||
subject(:register_as) { registerable_class.register_as(name, options) } | ||
let(:name) { :foo } | ||
let(:options) { {} } | ||
|
||
context 'when a registry' do | ||
context 'is provided' do | ||
let(:options) { { registry: registry } } | ||
let(:registry) { instance_double(Datadog::Registry) } | ||
|
||
it do | ||
expect(registry).to receive(:add) | ||
.with(name, a_kind_of(registerable_class), false) | ||
register_as | ||
end | ||
end | ||
|
||
context 'is not provided' do | ||
it do | ||
expect(Datadog.registry).to receive(:add) | ||
.with(name, a_kind_of(registerable_class), false) | ||
register_as | ||
end | ||
end | ||
end | ||
|
||
context 'when auto_patch' do | ||
context 'is provided' do | ||
let(:options) { { auto_patch: true } } | ||
|
||
it do | ||
expect(Datadog.registry).to receive(:add) | ||
.with(name, a_kind_of(registerable_class), true) | ||
register_as | ||
end | ||
end | ||
|
||
context 'is not provided' do | ||
it do | ||
expect(Datadog.registry).to receive(:add) | ||
.with(name, a_kind_of(registerable_class), false) | ||
register_as | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'instance behavior' do | ||
subject(:registerable_object) { registerable_class.new(name, options) } | ||
let(:name) { :foo } | ||
let(:options) { {} } | ||
|
||
it { is_expected.to have_attributes(name: name) } | ||
end | ||
end | ||
end |