Run spec tests on all supported OS

Also add resource coverage
This commit is contained in:
Cédric Defortis 2017-05-02 10:58:52 +02:00
parent ee0e095ea2
commit 3dd198e706
2 changed files with 46 additions and 77 deletions

View File

@ -1,74 +1,46 @@
# ex: syntax=ruby ts=2 sw=2 si et # ex: syntax=ruby ts=2 sw=2 si et
require 'spec_helper' require 'spec_helper'
require 'pp'
describe 'bind' do describe 'bind' do
context "on a Debian OS" do on_supported_os.each do |os, facts|
let :facts do context "on #{os}" do
{ let (:facts) {facts}
:concat_basedir => '/wtf', case facts[:os]['family']
:osfamily => 'Debian', when 'Debian'
:os => { expected_bind_tools_pkg = 'dnsutils'
:family => 'Debian', expected_bind_pkg = 'bind9'
}, expected_bind_service = 'bind9'
:operatingsystem => 'Debian' 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 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
end end

View File

@ -1,21 +1,18 @@
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts' require 'rspec-puppet-facts'
require 'rspec-puppet'
include RspecPuppetFacts include RspecPuppetFacts
require 'simplecov' require 'simplecov'
require 'simplecov-console' 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| RSpec.configure do |c|
c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml')) c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml'))
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end end
# Deal with missing fact in puppet firewall module
add_custom_fact :concat_basedir, '/tmp/concat/basedir'