-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from mocktools/develop
Ruby DnsMock v1.6.0
- Loading branch information
Showing
12 changed files
with
223 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
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module DnsMock | ||
module Record | ||
module Builder | ||
class Srv < DnsMock::Record::Builder::Base | ||
FACTORY_ARGS_ORDER = %i[priority weight port target].freeze | ||
|
||
def build | ||
records_data.map do |record_data| | ||
target_factory.new( | ||
record_data: record_data.values_at(*DnsMock::Record::Builder::Srv::FACTORY_ARGS_ORDER) | ||
).create | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module DnsMock | ||
module Record | ||
module Factory | ||
Srv = ::Class.new(DnsMock::Record::Factory::Base) do | ||
record_type :srv | ||
|
||
def instance_params | ||
record_data[0..-2] << create_dns_name(record_data.last) | ||
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module DnsMock | ||
VERSION = '1.5.18' | ||
VERSION = '1.6.0' | ||
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe DnsMock::Record::Builder::Srv do | ||
describe 'class dependencies' do | ||
subject(:builder_class) { described_class } | ||
|
||
it { is_expected.to be < DnsMock::Record::Builder::Base } | ||
it { is_expected.to be_const_defined(:FACTORY_ARGS_ORDER) } | ||
end | ||
|
||
describe '.call' do | ||
subject(:builder) { described_class.call(target_factory, records_data) } | ||
|
||
let(:target_factory) { class_double('TargetFactory') } | ||
let(:target_class_instance) { instance_double('TargetClass') } | ||
let(:target_factory_instance) { instance_double('TargetFactory', create: target_class_instance) } | ||
let(:records_data) do | ||
(1..8).each_slice(4).map do |chunk| | ||
DnsMock::Record::Builder::Srv::FACTORY_ARGS_ORDER.zip(chunk).to_h | ||
end | ||
end | ||
|
||
it 'returns array of target class instances' do | ||
records_data.each do |record_data| | ||
expect(target_factory) | ||
.to receive(:new) | ||
.with(record_data: record_data.values) | ||
.and_return(target_factory_instance) | ||
end | ||
expect(builder).to eq(::Array.new(records_data.size) { target_class_instance }) | ||
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe DnsMock::Record::Factory::Srv do | ||
it { expect(described_class).to be < DnsMock::Record::Factory::Base } | ||
|
||
describe '#instance_params' do | ||
subject(:instance_params) { described_class.new(record_data: record_data).instance_params } | ||
|
||
let(:int_params) { (0..3).to_a } | ||
let(:dns_name) { random_hostname } | ||
let(:record_data) { int_params + [dns_name] } | ||
let(:expected_data) do | ||
[ | ||
*int_params, | ||
create_dns_name(dns_name) | ||
] | ||
end | ||
|
||
it 'returns prepared target class instance params' do | ||
expect(instance_params).to eq(expected_data) | ||
end | ||
end | ||
|
||
describe '#create' do | ||
subject(:create_factory) { described_class.new(record_data: record_data.values).create } | ||
|
||
let(:record_data) do | ||
{ | ||
priority: 0, | ||
weight: 10, | ||
port: 5_060, | ||
target: target | ||
} | ||
end | ||
|
||
context 'when valid record context' do | ||
shared_examples 'returns instance of target class' do | ||
it 'returns instance of target class' do | ||
expect(DnsMock::Representer::Punycode).to receive(:call).with(target).and_call_original | ||
expect(create_factory).to be_an_instance_of(described_class.target_class) | ||
dns_names = record_data.slice(:target).transform_values do |value| | ||
create_dns_name(ascii_hostname ? value : to_punycode_hostname(value)) | ||
end | ||
record_data.merge(dns_names).each { |key, value| expect(create_factory.public_send(key)).to eq(value) } | ||
end | ||
end | ||
|
||
context 'when ASCII hostname' do | ||
let(:ascii_hostname) { true } | ||
let(:target) { random_hostname } | ||
|
||
include_examples 'returns instance of target class' | ||
end | ||
|
||
context 'when non ASCII hostname' do | ||
let(:ascii_hostname) { false } | ||
let(:target) { random_non_ascii_hostname } | ||
|
||
include_examples 'returns instance of target class' | ||
end | ||
end | ||
|
||
context 'when invalid record context' do | ||
context 'when invalid mname' do | ||
let(:target) { 42 } | ||
let(:error_context) { "cannot interpret as DNS name: #{target}. Invalid SRV record context" } | ||
|
||
it_behaves_like 'target class exception wrapper' | ||
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
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