spec tests for bind::key

This commit is contained in:
Cédric Defortis 2017-05-02 11:41:59 +02:00
parent 3dd198e706
commit 8308595a57
5 changed files with 126 additions and 23 deletions

View File

@ -1,6 +1,5 @@
# ex: syntax=ruby ts=2 sw=2 si et
require 'spec_helper'
require 'pp'
describe 'bind' do
on_supported_os.each do |os, facts|
@ -8,30 +7,60 @@ describe 'bind' do
let (:facts) {facts}
case facts[:os]['family']
when 'Debian'
expected_bind_tools_pkg = 'dnsutils'
expected_bind_pkg = 'bind9'
expected_bind_service = 'bind9'
expected_named_conf = '/etc/bind/named.conf'
expected_confdir = '/etc/bind'
when 'RedHat'
expected_bind_tools_pkg = 'bind-utils'
expected_bind_pkg = 'bind'
expected_bind_service = 'named'
expected_named_conf = '/etc/named.conf'
expected_confdir = '/etc/named'
end
context 'with defaults for all parameters' do
it { is_expected.to contain_class('bind::defaults') }
it { is_expected.to contain_class('bind::keydir') }
it { is_expected.to contain_class('bind::updater') }
it { is_expected.to contain_class('bind') }
it { is_expected.to compile.with_all_deps }
it do
is_expected.to contain_package('bind-tools').with({
ensure: 'present',
name: expected_bind_tools_pkg
})
end
it do
is_expected.to contain_package('bind').with({
ensure: 'latest',
name: expected_bind_pkg
})
end
it { is_expected.to contain_file('/usr/local/bin/dnssec-init') }
it do
is_expected.to contain_bind__key('rndc-key').with(
algorithm: 'hmac-md5',
secret_bits: '512',
keydir: expected_confdir,
keyfile: 'rndc.key',
)
end
it { is_expected.to contain_file('/usr/local/bin/rndc-helper') }
it { is_expected.to contain_concat("#{expected_confdir}/acls.conf") }
it { is_expected.to contain_concat("#{expected_confdir}/keys.conf") }
it { is_expected.to contain_concat("#{expected_confdir}/views.conf") }
it { is_expected.to contain_concat("#{expected_confdir}/servers.conf") }
it { is_expected.to contain_concat("#{expected_confdir}/logging.conf") }
it { is_expected.to contain_concat("#{expected_confdir}/view-mappings.txt") }
it { is_expected.to contain_concat("#{expected_confdir}/domain-mappings.txt") }
it do
is_expected.to contain_concat__fragment('bind-logging-header').with(
order: '00-header',
target: "#{expected_confdir}/logging.conf",
content: "logging {\n"
)
end
it do
is_expected.to contain_concat__fragment('bind-logging-footer').with(
order: '99-footer',
target: "#{expected_confdir}/logging.conf",
content: "};\n"
)
end
it { is_expected.to contain_file(expected_named_conf).that_requires('Package[bind]') }
it { is_expected.to contain_file(expected_named_conf).that_notifies('Service[bind]') }
it do

View File

@ -1,16 +1,25 @@
require 'spec_helper'
describe 'bind::updater' do
let :facts do
{
:concat_basedir => '/wtf',
:osfamily => 'Debian',
:os => {
:family => 'Debian',
},
:operatingsystem => 'Debian'
}
on_supported_os.each do |os, facts|
context "on #{os}" do
let (:facts) {facts}
case facts[:os]['family']
when 'Debian'
expected_bind_tools_pkg = 'dnsutils'
when 'RedHat'
expected_bind_tools_pkg = 'bind-utils'
end
context 'with defaults for all parameters' do
it { is_expected.to compile }
it { is_expected.to compile.with_all_deps }
end
it do
is_expected.to contain_package('bind-tools').with({
ensure: 'present',
name: expected_bind_tools_pkg
})
end
end
end
it { should compile }
it { should compile.with_all_deps }
end

40
spec/defines/key_spec.rb Normal file
View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe 'bind::key' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:pre_condition) do
'include bind'
end
let (:facts) {facts}
case facts[:os]['family']
when 'Debian'
expected_confdir = '/etc/bind'
expected_group = 'bind'
when 'RedHat'
expected_confdir = '/etc/named'
expected_group = 'named'
end
# Resource title:
let(:title) { 'foobar-key' }
context 'with defaults for all parameters' do
it { should compile }
it { should compile.with_all_deps }
it do
is_expected.to contain_file("#{expected_confdir}/keys/foobar-key").with(
owner: 'root',
group: expected_group,
content: /^key foobar-key/,
)
end
it do
is_expected.to contain_concat__fragment('bind-key-foobar-key').with(
order: '10',
target: "#{expected_confdir}/keys.conf",
content: "include \"#{expected_confdir}\/keys\/foobar-key\";\n",
)
end
end
end
end
end

28
spec/defines/zone_spec.rb Normal file
View File

@ -0,0 +1,28 @@
require 'spec_helper'
describe 'bind::zone' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let (:facts) {facts}
case facts[:os]['family']
when 'Debian'
expected_confdir = '/etc/bind'
expected_group = 'bind'
when 'RedHat'
expected_confdir = '/etc/named'
expected_group = 'named'
end
# Resource title:
let(:title) { 'foobar-zone' }
let(:params) do
{
zone_type: 'master'
}
end
context 'with defaults for all parameters' do
it { should compile }
it { should compile.with_all_deps }
end
end
end
end

View File

@ -4,9 +4,6 @@ require 'rspec-puppet'
include RspecPuppetFacts
require 'simplecov'
require 'simplecov-console'
RSpec.configure do |c|
c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml'))
c.after(:suite) do