Skip to content

Commit 0353d58

Browse files
committed
Fix Spec Test
1 parent b6f6208 commit 0353d58

10 files changed

+892
-1546
lines changed

spec/classes/openvpn_config_spec.rb

+22-27
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,35 @@
22

33
require 'spec_helper'
44

5-
describe 'openvpn::config', type: :class do
6-
on_supported_os.each do |os, facts|
5+
describe 'openvpn::config' do
6+
on_supported_os.each do |os, os_facts|
77
context "on #{os}" do
88
let(:facts) do
9-
facts
9+
os_facts.merge(
10+
easyrsa: '3.0'
11+
)
1012
end
1113

14+
let(:pre_condition) { 'include openvpn' } if os_facts[:os]['family'] == 'Debian'
15+
1216
it { is_expected.to compile.with_all_deps }
1317

14-
case facts[:os]['family']
18+
case os_facts[:os]['family']
1519
when 'Debian'
16-
context 'on Debian based machines' do
17-
it { is_expected.to contain_concat('/etc/default/openvpn') }
18-
it { is_expected.to contain_concat__fragment('openvpn.default.header') }
19-
20-
context 'enabled autostart_all' do
21-
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }
22-
23-
it {
24-
is_expected.to contain_concat__fragment('openvpn.default.header').with(
25-
'content' => %r{^AUTOSTART="all"}
26-
)
27-
}
28-
end
29-
30-
context 'disabled autostart_all' do
31-
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }
32-
33-
it {
34-
is_expected.to contain_concat__fragment('openvpn.default.header').with(
35-
'content' => %r{^AUTOSTART=""}
36-
)
37-
}
38-
end
20+
it { is_expected.to contain_concat('/etc/default/openvpn') }
21+
22+
it { is_expected.to contain_concat__fragment('openvpn.default.header') }
23+
24+
context 'enabled autostart_all' do
25+
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }
26+
27+
it { is_expected.to contain_concat__fragment('openvpn.default.header').with_content(%r{^AUTOSTART="all"}) }
28+
end
29+
30+
context 'disabled autostart_all' do
31+
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }
32+
33+
it { is_expected.to contain_concat__fragment('openvpn.default.header').with_content(%r{^AUTOSTART=""}) }
3934
end
4035
end
4136
end

spec/classes/openvpn_init_spec.rb

+15-20
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,30 @@
22

33
require 'spec_helper'
44

5-
describe 'openvpn', type: :class do
6-
on_supported_os.each do |os, facts|
5+
describe 'openvpn' do
6+
on_supported_os.each do |os, os_facts|
77
context "on #{os}" do
8-
let(:pre_condition) { 'class { "openvpn" : manage_service => true }' }
8+
let(:facts) do
9+
os_facts.merge(
10+
easyrsa: '3.0'
11+
)
12+
end
913

1014
it { is_expected.to compile.with_all_deps }
1115

12-
os_name = facts[:os]['name']
13-
os_release = facts[:os]['release']['major']
14-
case "#{os_name}-#{os_release}"
15-
when %r{FreeBSD}
16-
let(:facts) do
17-
facts
18-
end
16+
it { is_expected.to create_class('openvpn') }
17+
it { is_expected.to contain_class('openvpn::install') }
18+
it { is_expected.to contain_class('openvpn::config') }
1919

20-
context 'system without systemd' do
20+
if os_facts[:service_provider] == 'systemd'
21+
context 'system with systemd' do
2122
it { is_expected.to create_class('openvpn') }
22-
it { is_expected.to contain_class('openvpn::service') }
23+
it { is_expected.not_to contain_class('openvpn::service') }
2324
end
2425
else
25-
let(:facts) do
26-
facts.merge(
27-
service_provider: 'systemd'
28-
)
29-
end
30-
31-
context 'system with systemd' do
26+
context 'system without systemd' do
3227
it { is_expected.to create_class('openvpn') }
33-
it { is_expected.not_to contain_class('openvpn::service') }
28+
it { is_expected.to contain_class('openvpn::service') }
3429
end
3530
end
3631
end

spec/classes/openvpn_install_spec.rb

+25-18
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,43 @@
22

33
require 'spec_helper'
44

5-
describe 'openvpn::install', type: :class do
6-
on_supported_os.each do |os, facts|
5+
describe 'openvpn::install' do
6+
on_supported_os.each do |os, os_facts|
77
context "on #{os}" do
8-
let(:pre_condition) do
9-
'include openvpn'
10-
end
118
let(:facts) do
12-
facts
9+
os_facts.merge(
10+
easyrsa: '3.0'
11+
)
1312
end
13+
let(:pre_condition) { 'include openvpn' }
14+
15+
etc_directory = case os_facts[:os]['family']
16+
when 'Solaris'
17+
'/opt/local/etc'
18+
when 'FreeBSD'
19+
'/usr/local/etc'
20+
else
21+
'/etc'
22+
end
1423

1524
it { is_expected.to compile.with_all_deps }
1625

1726
it { is_expected.to create_class('openvpn::install') }
27+
1828
it { is_expected.to contain_package('openvpn') }
1929

20-
it { is_expected.to contain_file('/etc/openvpn').with('ensure' => 'directory') }
21-
it { is_expected.to contain_file('/etc/openvpn/keys').with('ensure' => 'directory') }
22-
it { is_expected.to contain_file('/var/log/openvpn').with('ensure' => 'directory') }
30+
it { is_expected.to contain_file("#{etc_directory}/openvpn").with_ensure('directory') }
31+
32+
it { is_expected.to contain_file("#{etc_directory}/openvpn/keys").with_ensure('directory') }
33+
34+
it { is_expected.to contain_file('/var/log/openvpn').with_ensure('directory') }
2335

2436
it { is_expected.to contain_package('easy-rsa') }
2537

26-
case facts[:os]['family']
27-
when 'Debian'
28-
context 'debian' do
29-
it { is_expected.to contain_package('openvpn-auth-ldap') }
30-
end
31-
when 'Archlinux'
32-
context 'Archlinux' do
33-
it { is_expected.not_to contain_package('openvpn-auth-ldap') }
34-
end
38+
if os_facts[:os]['family'] == 'Debian'
39+
it { is_expected.to contain_package('openvpn-auth-ldap') }
40+
else
41+
it { is_expected.not_to contain_package('openvpn-auth-ldap') }
3542
end
3643
end
3744
end

spec/classes/openvpn_service_spec.rb

+43-11
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,56 @@
22

33
require 'spec_helper'
44

5-
describe 'openvpn::service', type: :class do
6-
on_supported_os.each do |os, facts|
5+
describe 'openvpn::service' do
6+
on_supported_os.each do |os, os_facts|
77
context "on #{os}" do
8-
let(:pre_condition) { 'class { "openvpn": manage_service => true }' }
98
let(:facts) do
10-
facts
9+
os_facts.merge(
10+
easyrsa: '3.0'
11+
)
1112
end
13+
let(:pre_condition) { 'include openvpn' }
1214

1315
it { is_expected.to compile.with_all_deps }
1416

15-
it { is_expected.to create_class('openvpn::service') }
17+
context 'enabled manage_service and disabled namespecific_rclink' do
18+
let(:pre_condition) do
19+
'class { "openvpn":
20+
manage_service => true,
21+
namespecific_rclink => false
22+
}'
23+
end
1624

17-
it {
18-
is_expected.to contain_service('openvpn').with(
19-
'ensure' => 'running',
20-
'enable' => true
21-
)
22-
}
25+
it { is_expected.to create_class('openvpn::service') }
26+
27+
it { is_expected.to contain_service('openvpn').with_ensure('running').with_enable(true) }
28+
end
29+
30+
context 'disabled manage_service and disabled namespecific_rclink' do
31+
let(:pre_condition) do
32+
'class { "openvpn":
33+
manage_service => false,
34+
namespecific_rclink => false
35+
}'
36+
end
37+
38+
it { is_expected.to create_class('openvpn::service') }
39+
40+
it { is_expected.not_to contain_service('openvpn') }
41+
end
42+
43+
context 'disabled manage_service and enabled namespecific_rclink' do
44+
let(:pre_condition) do
45+
'class { "openvpn":
46+
manage_service => false,
47+
namespecific_rclink => true
48+
}'
49+
end
50+
51+
it { is_expected.to create_class('openvpn::service') }
52+
53+
it { is_expected.not_to contain_service('openvpn') }
54+
end
2355
end
2456
end
2557
end

0 commit comments

Comments
 (0)