From 3dd198e7064bdf908dd05f26810327881b6bdf3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Defortis?= Date: Tue, 2 May 2017 10:58:52 +0200 Subject: [PATCH] Run spec tests on all supported OS Also add resource coverage --- spec/classes/bind_spec.rb | 106 ++++++++++++++------------------------ spec/spec_helper.rb | 17 +++--- 2 files changed, 46 insertions(+), 77 deletions(-) diff --git a/spec/classes/bind_spec.rb b/spec/classes/bind_spec.rb index 569dc7c..86dfaa2 100644 --- a/spec/classes/bind_spec.rb +++ b/spec/classes/bind_spec.rb @@ -1,74 +1,46 @@ # ex: syntax=ruby ts=2 sw=2 si et require 'spec_helper' +require 'pp' describe 'bind' do - context "on a Debian OS" 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' + expected_bind_pkg = 'bind9' + expected_bind_service = 'bind9' + expected_named_conf = '/etc/bind/named.conf' + when 'RedHat' + expected_bind_tools_pkg = 'bind-utils' + expected_bind_pkg = 'bind' + expected_bind_service = 'named' + expected_named_conf = '/etc/named.conf' + end + context 'with defaults for all parameters' do + 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(expected_named_conf).that_requires('Package[bind]') } + it { is_expected.to contain_file(expected_named_conf).that_notifies('Service[bind]') } + it do + is_expected.to contain_service('bind').with({ + ensure: 'running', + name: expected_bind_service + }) + end + end end - it { is_expected.to compile } - it do - should contain_package('bind-tools').with({ - ensure: 'present', - name: 'dnsutils' - }) - end - it do - should contain_package('bind').with({ - ensure: 'latest', - name: 'bind9' - }) - end - - it { should contain_file('/etc/bind/named.conf').that_requires('Package[bind]') } - it { should contain_file('/etc/bind/named.conf').that_notifies('Service[bind]') } - - it { - should contain_service('bind').with({ - ensure: 'running', - name: 'bind9' - }) - } - end - context "on a RedHat OS" do - let :facts do - { - :concat_basedir => '/wtf', - :osfamily => 'RedHat', - :os => { - :family => 'RedHat', - }, - :operatingsystem => 'CentOS' - } - end - it { - should contain_package('bind-tools').with({ - 'ensure' => 'present', - 'name' => 'bind-utils' - }) - } - it { - should contain_package('bind').with({ - 'ensure' => 'latest', - 'name' => 'bind' - }) - } - - it { should contain_file('/etc/named.conf').that_requires('Package[bind]') } - it { should contain_file('/etc/named.conf').that_notifies('Service[bind]') } - - it { - should contain_service('bind').with({ - 'ensure' => 'running', - 'name' => 'named' - }) - } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 168db47..d4de420 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,21 +1,18 @@ - require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' +require 'rspec-puppet' include RspecPuppetFacts require 'simplecov' require 'simplecov-console' -SimpleCov.start do - add_filter '/spec' - add_filter '/vendor' - formatter SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ]) -end - RSpec.configure do |c| c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml')) + c.after(:suite) do + RSpec::Puppet::Coverage.report! + end end + +# Deal with missing fact in puppet firewall module +add_custom_fact :concat_basedir, '/tmp/concat/basedir'