Skip to content

Commit cae1372

Browse files
committed
update unit tests with rspec-puppet-facts
1 parent 91382fb commit cae1372

15 files changed

+1590
-1473
lines changed

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
$easyrsa_source = '/usr/share/easy-rsa/'
9393
$group = 'nobody'
9494
$ldap_auth_plugin_location = undef # unsupported
95+
$pam_module_path = undef
9596
$link_openssl_cnf = true
9697
$systemd = true
9798
$namespecific_rclink = false

manifests/server.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
Optional[String] $group = undef,
455455
Boolean $ipp = false,
456456
Boolean $duplicate_cn = false,
457-
String $local = $::ipaddress_eth0,
457+
String $local = $facts['ipaddress_eth0'],
458458
Variant[Boolean, String] $logfile = false,
459459
String $port = '1194',
460460
Optional[String] $portshare = undef,
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
require 'spec_helper'
22

33
describe 'openvpn::config', type: :class do
4-
context 'on Debian based machines' do
5-
let(:facts) do
6-
{
7-
os: { 'family' => 'Debian' },
8-
os: { 'name' => 'Ubuntu' },
9-
os: { 'release' => {'major' => '16.04' } },
10-
concat_basedir: '/var/lib/puppet/concat'
11-
}
12-
end
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:facts) do
7+
facts
8+
end
139

14-
it { is_expected.to contain_concat('/etc/default/openvpn') }
15-
it { is_expected.to contain_concat__fragment('openvpn.default.header') }
10+
it { is_expected.to compile.with_all_deps }
1611

17-
context 'enabled autostart_all' do
18-
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }
12+
case facts[:os]['family']
13+
when 'Debian'
14+
context 'on Debian based machines' do
15+
it { is_expected.to contain_concat('/etc/default/openvpn') }
16+
it { is_expected.to contain_concat__fragment('openvpn.default.header') }
1917

20-
it {
21-
is_expected.to contain_concat__fragment('openvpn.default.header').with(
22-
'content' => %r{^AUTOSTART="all"}
23-
)
24-
}
25-
end
18+
context 'enabled autostart_all' do
19+
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }
20+
21+
it {
22+
is_expected.to contain_concat__fragment('openvpn.default.header').with(
23+
'content' => %r{^AUTOSTART="all"}
24+
)
25+
}
26+
end
2627

27-
context 'disabled autostart_all' do
28-
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }
28+
context 'disabled autostart_all' do
29+
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }
2930

30-
it {
31-
is_expected.to contain_concat__fragment('openvpn.default.header').with(
32-
'content' => %r{^AUTOSTART=""}
33-
)
34-
}
31+
it {
32+
is_expected.to contain_concat__fragment('openvpn.default.header').with(
33+
'content' => %r{^AUTOSTART=""}
34+
)
35+
}
36+
end
37+
end
38+
end
3539
end
3640
end
3741
end
Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,87 @@
11
require 'spec_helper'
22

33
describe 'openvpn', type: :class do
4-
let(:title) { 'test openvpn hiera lookups' }
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:pre_condition) { 'class { "openvpn" : manage_service => true }' }
7+
let(:facts) do
8+
facts
9+
end
10+
let(:title) { 'test openvpn hiera lookups' }
511

6-
let(:facts) do
7-
{
8-
concat_basedir: '/var/lib/puppet/concat',
9-
osfamily: 'Debian',
10-
operatingsystem: 'Ubuntu',
11-
operatingsystemrelease: '12.04'
12-
}
13-
end
12+
it { is_expected.to create_class('openvpn') }
1413

15-
it { is_expected.to create_class('openvpn') }
16-
it { is_expected.to contain_class('openvpn::service') }
14+
it do
15+
is_expected.to contain_openvpn__server('winterthur').with(
16+
'country' => 'CH',
17+
'province' => 'ZH',
18+
'city' => 'Winterthur',
19+
'organization' => 'example.org',
20+
'email' => '[email protected]',
21+
'server' => '10.200.200.0 255.255.255.0'
22+
)
23+
end
1724

18-
it do
19-
is_expected.to contain_openvpn__server('winterthur').with(
20-
'country' => 'CH',
21-
'province' => 'ZH',
22-
'city' => 'Winterthur',
23-
'organization' => 'example.org',
24-
'email' => 'root@example.org',
25-
'server' => '10.200.200.0 255.255.255.0'
26-
)
27-
end
25+
it do
26+
is_expected.to contain_openvpn__server('uster').with(
27+
'country' => 'CH',
28+
'province' => 'ZH',
29+
'city' => 'Uster',
30+
'organization' => 'example.com',
31+
'email' => 'root@example.com',
32+
'server' => '10.100.100.0 255.255.255.0'
33+
)
34+
end
2835

29-
it do
30-
is_expected.to contain_openvpn__server('uster').with(
31-
'country' => 'CH',
32-
'province' => 'ZH',
33-
'city' => 'Uster',
34-
'organization' => 'example.com',
35-
'email' => '[email protected]',
36-
'server' => '10.100.100.0 255.255.255.0'
37-
)
38-
end
36+
it do
37+
is_expected.to contain_openvpn__client('winti-client1').with(
38+
'server' => 'winterthur'
39+
)
40+
end
3941

40-
it do
41-
is_expected.to contain_openvpn__client('winti-client1').with(
42-
'server' => 'winterthur'
43-
)
44-
end
42+
it do
43+
is_expected.to contain_openvpn__client('winti-client2').with(
44+
'server' => 'winterthur'
45+
)
46+
end
4547

46-
it do
47-
is_expected.to contain_openvpn__client('winti-client2').with(
48-
'server' => 'winterthur'
49-
)
50-
end
48+
it do
49+
is_expected.to contain_openvpn__client('uster-client1').with(
50+
'server' => 'uster'
51+
)
52+
end
5153

52-
it do
53-
is_expected.to contain_openvpn__client('uster-client1').with(
54-
'server' => 'uster'
55-
)
56-
end
54+
it do
55+
is_expected.to contain_openvpn__client('uster-client2').with(
56+
'server' => 'uster'
57+
)
58+
end
5759

58-
it do
59-
is_expected.to contain_openvpn__client('uster-client2').with(
60-
'server' => 'uster'
61-
)
62-
end
60+
it do
61+
is_expected.to contain_openvpn__client_specific_config('winti-client1').with(
62+
'server' => 'winterthur',
63+
'ifconfig' => '10.200.200.50 10.200.200.51'
64+
)
65+
end
6366

64-
it do
65-
is_expected.to contain_openvpn__client_specific_config('winti-client1').with(
66-
'server' => 'winterthur',
67-
'ifconfig' => '10.200.200.50 10.200.200.51'
68-
)
69-
end
67+
it do
68+
is_expected.to contain_openvpn__client_specific_config('uster-client1').with(
69+
'server' => 'uster',
70+
'ifconfig' => '10.100.100.50 10.100.100.51'
71+
)
72+
end
7073

71-
it do
72-
is_expected.to contain_openvpn__client_specific_config('uster-client1').with(
73-
'server' => 'uster',
74-
'ifconfig' => '10.100.100.50 10.100.100.51'
75-
)
76-
end
77-
78-
it do
79-
is_expected.to contain_openvpn__revoke('winti-client2').with(
80-
'server' => 'winterthur'
81-
)
82-
end
74+
it do
75+
is_expected.to contain_openvpn__revoke('winti-client2').with(
76+
'server' => 'winterthur'
77+
)
78+
end
8379

84-
it do
85-
is_expected.to contain_openvpn__revoke('uster-client2').with(
86-
'server' => 'uster'
87-
)
80+
it do
81+
is_expected.to contain_openvpn__revoke('uster-client2').with(
82+
'server' => 'uster'
83+
)
84+
end
85+
end
8886
end
8987
end

spec/classes/openvpn_init_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
require 'spec_helper'
22

33
describe 'openvpn', type: :class do
4-
context 'non-systemd systems' do
5-
let(:facts) do
6-
{
7-
concat_basedir: '/var/lib/puppet/concat',
8-
os: { 'family' => 'Debian' },
9-
os: { 'name' => 'Ubuntu' },
10-
os: { 'release' => {'major' => '16.04' } },
11-
}
12-
end
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:pre_condition) { 'class { "openvpn" : manage_service => true }' }
7+
let(:facts) do
8+
facts
9+
end
1310

14-
it { is_expected.to create_class('openvpn') }
15-
it { is_expected.to contain_class('openvpn::service') }
16-
end
11+
it { is_expected.to compile.with_all_deps }
1712

18-
context 'systemd systems' do
19-
let(:facts) do
20-
{
21-
concat_basedir: '/var/lib/puppet/concat',
22-
os: { 'family' => 'RedHat' },
23-
os: { 'name' => 'CentOS' },
24-
os: { 'release' => {'major' => '7' } },
25-
}
13+
os_name = facts[:os]['name']
14+
os_release = facts[:os]['release']['major']
15+
case "#{os_name}-#{os_release}"
16+
when 'Ubuntu-14.04', 'CentOS-6', 'RedHat-6', %r{FreeBSD}
17+
context 'system without systemd' do
18+
it { is_expected.to create_class('openvpn') }
19+
it { is_expected.to contain_class('openvpn::service') }
20+
end
21+
when 'Ubuntu-16.04', 'CentOS-7', 'RedHat-7', 'Debian-8', 'Debian-9', %r{Archlinux}
22+
context 'system with systemd' do
23+
it { is_expected.to create_class('openvpn') }
24+
it { is_expected.not_to contain_class('openvpn::service') }
25+
end
26+
else
27+
context 'unsupported systems' do
28+
it { is_expected.to raise_error(%r{unsupported OS}) }
29+
end
30+
end
2631
end
27-
28-
it { is_expected.to create_class('openvpn') }
29-
it { is_expected.not_to contain_class('openvpn::service') }
3032
end
3133
end

0 commit comments

Comments
 (0)