From 8308595a57837d8618194b818c074598dc67ced7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Defortis?= Date: Tue, 2 May 2017 11:41:59 +0200 Subject: [PATCH] spec tests for bind::key --- spec/classes/bind_spec.rb | 47 +++++++++++++++++++++++++++++------- spec/classes/updater_spec.rb | 31 +++++++++++++++--------- spec/defines/key_spec.rb | 40 ++++++++++++++++++++++++++++++ spec/defines/zone_spec.rb | 28 +++++++++++++++++++++ spec/spec_helper.rb | 3 --- 5 files changed, 126 insertions(+), 23 deletions(-) create mode 100644 spec/defines/key_spec.rb create mode 100644 spec/defines/zone_spec.rb diff --git a/spec/classes/bind_spec.rb b/spec/classes/bind_spec.rb index 86dfaa2..70a4b2d 100644 --- a/spec/classes/bind_spec.rb +++ b/spec/classes/bind_spec.rb @@ -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 diff --git a/spec/classes/updater_spec.rb b/spec/classes/updater_spec.rb index 738571b..64d4604 100644 --- a/spec/classes/updater_spec.rb +++ b/spec/classes/updater_spec.rb @@ -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 diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb new file mode 100644 index 0000000..d4422f7 --- /dev/null +++ b/spec/defines/key_spec.rb @@ -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 diff --git a/spec/defines/zone_spec.rb b/spec/defines/zone_spec.rb new file mode 100644 index 0000000..3ca0e3c --- /dev/null +++ b/spec/defines/zone_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d4de420..74dac10 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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