Skip to content

Commit

Permalink
update unit tests with rspec-puppet-facts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan33l committed Sep 26, 2018
1 parent 91382fb commit cae1372
Show file tree
Hide file tree
Showing 15 changed files with 1,590 additions and 1,473 deletions.
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
$easyrsa_source = '/usr/share/easy-rsa/'
$group = 'nobody'
$ldap_auth_plugin_location = undef # unsupported
$pam_module_path = undef
$link_openssl_cnf = true
$systemd = true
$namespecific_rclink = false
Expand Down
2 changes: 1 addition & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
Optional[String] $group = undef,
Boolean $ipp = false,
Boolean $duplicate_cn = false,
String $local = $::ipaddress_eth0,
String $local = $facts['ipaddress_eth0'],
Variant[Boolean, String] $logfile = false,
String $port = '1194',
Optional[String] $portshare = undef,
Expand Down
56 changes: 30 additions & 26 deletions spec/classes/openvpn_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
require 'spec_helper'

describe 'openvpn::config', type: :class do
context 'on Debian based machines' do
let(:facts) do
{
os: { 'family' => 'Debian' },
os: { 'name' => 'Ubuntu' },
os: { 'release' => {'major' => '16.04' } },
concat_basedir: '/var/lib/puppet/concat'
}
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

it { is_expected.to contain_concat('/etc/default/openvpn') }
it { is_expected.to contain_concat__fragment('openvpn.default.header') }
it { is_expected.to compile.with_all_deps }

context 'enabled autostart_all' do
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }
case facts[:os]['family']
when 'Debian'
context 'on Debian based machines' do
it { is_expected.to contain_concat('/etc/default/openvpn') }
it { is_expected.to contain_concat__fragment('openvpn.default.header') }

it {
is_expected.to contain_concat__fragment('openvpn.default.header').with(
'content' => %r{^AUTOSTART="all"}
)
}
end
context 'enabled autostart_all' do
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }

it {
is_expected.to contain_concat__fragment('openvpn.default.header').with(
'content' => %r{^AUTOSTART="all"}
)
}
end

context 'disabled autostart_all' do
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }
context 'disabled autostart_all' do
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }

it {
is_expected.to contain_concat__fragment('openvpn.default.header').with(
'content' => %r{^AUTOSTART=""}
)
}
it {
is_expected.to contain_concat__fragment('openvpn.default.header').with(
'content' => %r{^AUTOSTART=""}
)
}
end
end
end
end
end
end
144 changes: 71 additions & 73 deletions spec/classes/openvpn_init_hiera_spec.rb
Original file line number Diff line number Diff line change
@@ -1,89 +1,87 @@
require 'spec_helper'

describe 'openvpn', type: :class do
let(:title) { 'test openvpn hiera lookups' }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:pre_condition) { 'class { "openvpn" : manage_service => true }' }
let(:facts) do
facts
end
let(:title) { 'test openvpn hiera lookups' }

let(:facts) do
{
concat_basedir: '/var/lib/puppet/concat',
osfamily: 'Debian',
operatingsystem: 'Ubuntu',
operatingsystemrelease: '12.04'
}
end
it { is_expected.to create_class('openvpn') }

it { is_expected.to create_class('openvpn') }
it { is_expected.to contain_class('openvpn::service') }
it do
is_expected.to contain_openvpn__server('winterthur').with(
'country' => 'CH',
'province' => 'ZH',
'city' => 'Winterthur',
'organization' => 'example.org',
'email' => '[email protected]',
'server' => '10.200.200.0 255.255.255.0'
)
end

it do
is_expected.to contain_openvpn__server('winterthur').with(
'country' => 'CH',
'province' => 'ZH',
'city' => 'Winterthur',
'organization' => 'example.org',
'email' => 'root@example.org',
'server' => '10.200.200.0 255.255.255.0'
)
end
it do
is_expected.to contain_openvpn__server('uster').with(
'country' => 'CH',
'province' => 'ZH',
'city' => 'Uster',
'organization' => 'example.com',
'email' => 'root@example.com',
'server' => '10.100.100.0 255.255.255.0'
)
end

it do
is_expected.to contain_openvpn__server('uster').with(
'country' => 'CH',
'province' => 'ZH',
'city' => 'Uster',
'organization' => 'example.com',
'email' => '[email protected]',
'server' => '10.100.100.0 255.255.255.0'
)
end
it do
is_expected.to contain_openvpn__client('winti-client1').with(
'server' => 'winterthur'
)
end

it do
is_expected.to contain_openvpn__client('winti-client1').with(
'server' => 'winterthur'
)
end
it do
is_expected.to contain_openvpn__client('winti-client2').with(
'server' => 'winterthur'
)
end

it do
is_expected.to contain_openvpn__client('winti-client2').with(
'server' => 'winterthur'
)
end
it do
is_expected.to contain_openvpn__client('uster-client1').with(
'server' => 'uster'
)
end

it do
is_expected.to contain_openvpn__client('uster-client1').with(
'server' => 'uster'
)
end
it do
is_expected.to contain_openvpn__client('uster-client2').with(
'server' => 'uster'
)
end

it do
is_expected.to contain_openvpn__client('uster-client2').with(
'server' => 'uster'
)
end
it do
is_expected.to contain_openvpn__client_specific_config('winti-client1').with(
'server' => 'winterthur',
'ifconfig' => '10.200.200.50 10.200.200.51'
)
end

it do
is_expected.to contain_openvpn__client_specific_config('winti-client1').with(
'server' => 'winterthur',
'ifconfig' => '10.200.200.50 10.200.200.51'
)
end
it do
is_expected.to contain_openvpn__client_specific_config('uster-client1').with(
'server' => 'uster',
'ifconfig' => '10.100.100.50 10.100.100.51'
)
end

it do
is_expected.to contain_openvpn__client_specific_config('uster-client1').with(
'server' => 'uster',
'ifconfig' => '10.100.100.50 10.100.100.51'
)
end

it do
is_expected.to contain_openvpn__revoke('winti-client2').with(
'server' => 'winterthur'
)
end
it do
is_expected.to contain_openvpn__revoke('winti-client2').with(
'server' => 'winterthur'
)
end

it do
is_expected.to contain_openvpn__revoke('uster-client2').with(
'server' => 'uster'
)
it do
is_expected.to contain_openvpn__revoke('uster-client2').with(
'server' => 'uster'
)
end
end
end
end
48 changes: 25 additions & 23 deletions spec/classes/openvpn_init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
require 'spec_helper'

describe 'openvpn', type: :class do
context 'non-systemd systems' do
let(:facts) do
{
concat_basedir: '/var/lib/puppet/concat',
os: { 'family' => 'Debian' },
os: { 'name' => 'Ubuntu' },
os: { 'release' => {'major' => '16.04' } },
}
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:pre_condition) { 'class { "openvpn" : manage_service => true }' }
let(:facts) do
facts
end

it { is_expected.to create_class('openvpn') }
it { is_expected.to contain_class('openvpn::service') }
end
it { is_expected.to compile.with_all_deps }

context 'systemd systems' do
let(:facts) do
{
concat_basedir: '/var/lib/puppet/concat',
os: { 'family' => 'RedHat' },
os: { 'name' => 'CentOS' },
os: { 'release' => {'major' => '7' } },
}
os_name = facts[:os]['name']
os_release = facts[:os]['release']['major']
case "#{os_name}-#{os_release}"
when 'Ubuntu-14.04', 'CentOS-6', 'RedHat-6', %r{FreeBSD}
context 'system without systemd' do
it { is_expected.to create_class('openvpn') }
it { is_expected.to contain_class('openvpn::service') }
end
when 'Ubuntu-16.04', 'CentOS-7', 'RedHat-7', 'Debian-8', 'Debian-9', %r{Archlinux}
context 'system with systemd' do
it { is_expected.to create_class('openvpn') }
it { is_expected.not_to contain_class('openvpn::service') }
end
else
context 'unsupported systems' do
it { is_expected.to raise_error(%r{unsupported OS}) }
end
end
end

it { is_expected.to create_class('openvpn') }
it { is_expected.not_to contain_class('openvpn::service') }
end
end
Loading

0 comments on commit cae1372

Please sign in to comment.