Skip to content

Commit

Permalink
Merge pull request #224 from bastelfreak/updaterspec
Browse files Browse the repository at this point in the history
Introduce rspec-puppet-facts for some tests
  • Loading branch information
igalic committed May 19, 2016
2 parents 76aef35 + 6b9b7d0 commit df89e6c
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 149 deletions.
6 changes: 6 additions & 0 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
$ldap_clientkey = $zabbix::params::ldap_clientkey,
$puppetgem = $zabbix::params::puppetgem,
) inherits zabbix::params {

# check osfamily, Arch is currently not supported for web
if $::osfamily == 'Archlinux' {
fail('Archlinux is currently not supported for zabbix::web ')
}

$apache_user = getvar('::apache::user')
$apache_group = getvar('::apache::group')

Expand Down
4 changes: 2 additions & 2 deletions spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
end
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
let :facts do
facts.merge(
is_pe: false
mocked_facts
)
end
context 'with all defaults' do
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
end
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
let :facts do
facts.merge(
is_pe: false
mocked_facts
)
end
context 'with all defaults' do
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/userparameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
end
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
facts
let :facts do
facts.merge(
mocked_facts
)
end
context 'with all defaults' do
it { should contain_class('zabbix::userparameter') }
Expand Down
256 changes: 113 additions & 143 deletions spec/classes/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,154 +14,124 @@ def package_provider_for_gems
zabbix_url: 'zabbix.example.com'
}
end

# Running an RedHat OS.
context 'On a RedHat OS' do
let :facts do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '6.5',
operatingsystemmajrelease: '6',
architecture: 'x86_64',
lsbdistid: 'RedHat',
concat_basedir: '/tmp',
is_pe: false,
puppetversion: Puppet.version,
facterversion: Facter.version,
ipaddress: '192.168.1.10',
lsbdistcodename: '',
id: 'root',
kernel: 'Linux',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin',
selinux_config_mode: ''
}
end

describe 'with default settings' do
it { should contain_file('/etc/zabbix/web').with_ensure('directory') }
it { should_not contain_selboolean('httpd_can_connect_zabbix') }
end

describe 'with enabled selinux' do
on_supported_os.each do |os, facts|
context "on #{os} " do
let :facts do
super().merge(selinux_config_mode: 'enforcing')
end
it { should contain_selboolean('httpd_can_connect_zabbix').with('value' => 'on', 'persistent' => true) }
end

describe 'with database_type as postgresql' do
let :params do
super().merge(database_type: 'postgresql')
end

it { should contain_package('zabbix-web-pgsql').with_name('zabbix-web-pgsql') }
it { should contain_package('zabbix-web') }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['TYPE'\] = 'POSTGRESQL'/) }
end

describe 'with database_type as mysql' do
let :params do
super().merge(database_type: 'mysql')
end

it { should contain_package('zabbix-web-mysql').with_name('zabbix-web-mysql') }
it { should contain_package('zabbix-web') }
end

it { should contain_file('/etc/zabbix/web/zabbix.conf.php') }

describe 'when manage_resources is true' do
let :params do
super().merge(
manage_resources: true
)
end

it { should contain_class('zabbix::resources::web') }
it { should contain_package('zabbixapi').that_requires('Class[ruby::dev]').with_provider(package_provider_for_gems) }
it { should contain_class('ruby::dev') }
it { should contain_file('/etc/zabbix/imported_templates').with_ensure('directory') }
end

describe 'when manage_resources and is_pe are true' do
let :facts do
super().merge(
is_pe: true,
pe_version: '3.7.0'
facts.merge(
mocked_facts
)
end

let :params do
super().merge(manage_resources: true)
end

it { should contain_package('zabbixapi').with_provider('pe_puppetserver_gem') }
end

describe 'when manage_resources is false' do
let :params do
super().merge(manage_resources: false)
if facts[:osfamily] == 'Archlinux'
context 'with all defaults' do
it { is_expected.not_to compile }
end
else
context 'with all defaults' do
it { should compile.with_all_deps }
it { should contain_file('/etc/zabbix/web').with_ensure('directory') }
end

describe 'with enforcing selinux' do
let :facts do
super().merge(selinux_config_mode: 'enforcing')
end
if facts[:osfamily] == 'RedHat'
it { should contain_selboolean('httpd_can_connect_zabbix').with('value' => 'on', 'persistent' => true) }
else
it { should_not contain_selboolean('httpd_can_connect_zabbix') }
end
end

%w(permissive disabled).each do |mode|
describe "with #{mode} selinux" do
let :facts do
super().merge(selinux_config_mode: mode)
end
it { should_not contain_selboolean('httpd_can_connect_zabbix') }
end
end

describe 'with database_type as postgresql' do
let :params do
super().merge(database_type: 'postgresql')
end
packages = facts[:osfamily] == 'RedHat' ? ['zabbix-web-pgsql', 'zabbix-web'] : ['zabbix-frontend-php', 'php5-pgsql']
packages.each do |package|
it { should contain_package(package) }
end
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['TYPE'\] = 'POSTGRESQL'/) }
end

describe 'with database_type as mysql' do
let :params do
super().merge(database_type: 'mysql')
end
packages = facts[:osfamily] == 'RedHat' ? ['zabbix-web-mysql', 'zabbix-web'] : ['zabbix-frontend-php', 'php5-mysql']
packages.each do |package|
it { should contain_package(package) }
end
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['TYPE'\] = 'MYSQL'/) }
end

it { should contain_file('/etc/zabbix/web/zabbix.conf.php') }

describe 'when manage_resources is true' do
let :params do
super().merge(
manage_resources: true
)
end

it { should contain_class('zabbix::resources::web') }
it { should contain_package('zabbixapi').that_requires('Class[ruby::dev]').with_provider(package_provider_for_gems) }
it { should contain_class('ruby::dev') }
it { should contain_file('/etc/zabbix/imported_templates').with_ensure('directory') }
end

describe 'when manage_resources and is_pe are true' do
let :facts do
super().merge(
is_pe: true,
pe_version: '3.7.0'
)
end

let :params do
super().merge(manage_resources: true)
end

it { should contain_package('zabbixapi').with_provider('pe_puppetserver_gem') }
end

describe 'when manage_resources is false' do
let :params do
super().merge(manage_resources: false)
end

it { should_not contain_class('zabbix::resources::web') }
end

it { should contain_apache__vhost('zabbix.example.com').with_name('zabbix.example.com') }

context 'with database_* settings' do
let :params do
super().merge(
database_host: 'localhost',
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
zabbix_server: 'localhost'
)
end

it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['SERVER'\] = 'localhost'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['DATABASE'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['USER'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['PASSWORD'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$ZBX_SERVER = 'localhost'/) }
end
end

it { should_not contain_class('zabbix::resources::web') }
end

it { should contain_apache__vhost('zabbix.example.com').with_name('zabbix.example.com') }

context 'with database_* settings' do
let :params do
super().merge(
database_host: 'localhost',
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
zabbix_server: 'localhost'
)
end

it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['SERVER'\] = 'localhost'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['DATABASE'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['USER'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$DB\['PASSWORD'\] = 'zabbix-server'/) }
it { should contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(/^\$ZBX_SERVER = 'localhost'/) }
end
end
end

describe 'zabbix::web' do
let :node do
'rspec.puppet.com'
end

let :params do
{
zabbix_url: 'zabbix.example.com'
}
end

context 'On Debian 6.0' do
let :facts do
{
osfamily: 'debian',
operatingsystem: 'debian',
operatingsystemrelease: '6.0',
operatingsystemmajrelease: '6',
architecture: 'x86_64',
lsbdistid: 'debian',
concat_basedir: '/tmp',
is_pe: false,
puppetversion: Puppet.version,
facterversion: Facter.version,
ipaddress: '192.168.1.10',
lsbdistcodename: 'squeeze',
id: 'root',
kernel: 'Linux',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin',
selinux_config_mode: ''
}
end

it { should contain_package('zabbix-frontend-php') }
end
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

def mocked_facts
{
concat_basedir: '/tmp',
is_pe: false,
selinux_config_mode: 'disabled'
}
end

0 comments on commit df89e6c

Please sign in to comment.