Added spec tests for Vmpooler::Dns

This commit is contained in:
Jake Spain 2023-02-23 15:53:35 -05:00
parent fb80d989c8
commit 91248fe23a
No known key found for this signature in database
GPG key ID: BC1C4DA0A085E113
3 changed files with 83 additions and 123 deletions

62
spec/unit/dns_spec.rb Normal file
View file

@ -0,0 +1,62 @@
require 'spec_helper'
describe 'Vmpooler::Dns' do
let(:dns_class) { 'mock-dnsservice' }
let(:dns_config_name) { 'mock' }
let(:pool) { 'pool1' }
let(:config) { YAML.load(<<~EOT
---
:dns_configs:
:mock:
dns_class: 'mock'
domain: 'example.com'
:pools:
- name: 'pool1'
dns_plugin: 'mock'
EOT
)}
subject { Vmpooler::Dns.new }
describe '.get_dns_plugin_class_by_name' do
it 'returns the plugin class for the specified config' do
result = Vmpooler::Dns.get_dns_plugin_class_by_name(config, dns_config_name)
expect(result).to eq('mock')
end
end
describe '.get_domain_for_pool' do
it 'returns the domain for the specified pool' do
result = Vmpooler::Dns.get_domain_for_pool(config, pool)
expect(result).to eq('example.com')
end
end
describe '.get_dns_plugin_domain_by_name' do
it 'returns the domain for the specified config' do
result = Vmpooler::Dns.get_dns_plugin_domain_by_name(config, dns_config_name)
expect(result).to eq('example.com')
end
end
describe '.get_dns_plugin_config_classes' do
it 'returns the list of dns plugin classes' do
result = Vmpooler::Dns.get_dns_plugin_config_classes(config)
expect(result).to eq(['mock'])
end
end
describe '#load_from_gems' do
let(:gem_name) { 'mock-dnsservice' }
let(:translated_gem_name) { 'mock/dnsservice' }
before(:each) do
allow(subject).to receive(:require).with(gem_name).and_return(true)
end
it 'loads the specified gem' do
expect(subject).to receive(:require).with("vmpooler/dns/#{translated_gem_name}")
result = subject.load_from_gems(gem_name)
expect(result).to eq("vmpooler/dns/#{translated_gem_name}")
end
end
end

View file

@ -1,104 +1,11 @@
require 'spec_helper'
describe 'Parser' do
# The only method previously tested here was '#get_domain_for_pool'
# which was moved to Vmpooler::Dns as the more appropriate class
#
# TODO: Add tests for last remaining method, or move to more appropriate class
describe 'Vmpooler::Parsing' do
let(:pool) { 'pool1' }
subject { Vmpooler::Parsing }
describe '.get_domain_for_pool' do
let(:provider_name) { 'mock_provider' }
context 'No provider is set' do
let(:config) { YAML.load(<<~EOT
---
:config:
:providers:
:mock_provider:
:pools:
- name: '#{pool}'
size: 1
EOT
)}
it 'should return nil' do
result = subject.get_domain_for_pool(config, pool)
expect(result).to be_nil
end
end
context 'Provider is vsphere by default' do
let(:config) { YAML.load(<<~EOT
---
:config:
:providers:
:vsphere:
domain: myown.com
:pools:
- name: '#{pool}'
size: 1
EOT
)}
it 'should return the domain set for vsphere' do
result = subject.get_domain_for_pool(config, pool)
expect(result).to eq('myown.com')
end
end
context 'No domain is set' do
let(:config) { YAML.load(<<~EOT
---
:config:
:providers:
:mock_provider:
:pools:
- name: '#{pool}'
size: 1
provider: #{provider_name}
EOT
)}
it 'should return nil' do
result = subject.get_domain_for_pool(config, pool)
expect(result).to be_nil
end
end
context 'Only a global domain is set' do
let(:config) { YAML.load(<<~EOT
---
:config:
domain: example.com
:providers:
:mock_provider:
:pools:
- name: '#{pool}'
size: 1
provider: #{provider_name}
EOT
)}
it 'should return the domain set in the config section' do
result = subject.get_domain_for_pool(config, pool)
expect(result).to_not be_nil
expect(result).to eq('example.com')
end
end
context 'A provider specified a domain to use' do
let(:config) { YAML.load(<<~EOT
---
:config:
:providers:
:mock_provider:
domain: m.example.com
:pools:
- name: '#{pool}'
size: 1
provider: #{provider_name}
EOT
)}
it 'should return the domain set in the config section' do
result = subject.get_domain_for_pool(config, pool)
expect(result).to_not be_nil
expect(result).to eq('m.example.com')
end
end
end
end