Skip to content

Commit 537b9db

Browse files
author
Florent Poinsaut
committed
Fix tests
1 parent a19cf7d commit 537b9db

File tree

4 files changed

+24
-57
lines changed

4 files changed

+24
-57
lines changed

manifests/init.pp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
$package_ensure = $molly_guard::params::package_ensure,
66
$package_name = $molly_guard::params::package_name,
77
) inherits molly_guard::params {
8-
validate_bool($always_query_hostname)
8+
# <stringified variable handling>
9+
if is_string($always_query_hostname) == true {
10+
$always_query_hostname_bool = str2bool($always_query_hostname)
11+
} else {
12+
$always_query_hostname_bool = $always_query_hostname
13+
}
14+
# </stringified variable handling>
15+
16+
# <variable validations>
17+
validate_bool($always_query_hostname_bool)
18+
validate_string($package_ensure)
19+
validate_string($package_name)
20+
# </variable validations>
921

1022
anchor { "${module_name}::begin": } ->
1123
class { "${module_name}::install": } ->

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$package_name = 'molly-guard'
1111
}
1212
default: {
13-
fail("Unsupported OS family: ${::osfamily}")
13+
fail("molly_guard supports osfamilies Debian. Detected osfamily is <${::osfamily}>.")
1414
}
1515
}
1616
}

spec/classes/init_spec.rb

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66
:release => '6.0',
77
:majrelease => '6',
88
:lsbdistcodename => 'squeeze',
9-
:packages => 'molly-guard',
9+
:packages => 'molly_guard',
1010
},
1111
'debian7' =>
1212
{ :osfamily => 'Debian',
1313
:release => '7.0',
1414
:majrelease => '7',
1515
:lsbdistcodename => 'wheezy',
16-
:packages => 'molly-guard',
16+
:packages => 'molly_guard',
1717
},
1818
'debian8' =>
1919
{ :osfamily => 'Debian',
2020
:release => '8.0',
2121
:majrelease => '8',
2222
:lsbdistcodename => 'jessie',
23-
:packages => 'molly-guard',
23+
:packages => 'molly_guard',
2424
},
2525
'ubuntu1004' =>
2626
{ :osfamily => 'Debian',
2727
:release => '10.04',
2828
:majrelease => '10',
2929
:lsbdistcodename => 'lucid',
30-
:packages => 'molly-guard',
30+
:packages => 'molly_guard',
3131
},
3232
'ubuntu1204' =>
3333
{ :osfamily => 'Debian',
3434
:release => '12.04',
3535
:majrelease => '12',
3636
:lsbdistcodename => 'precise',
37-
:packages => 'molly-guard',
37+
:packages => 'molly_guard',
3838
},
3939
'ubuntu1404' =>
4040
{ :osfamily => 'Debian',
4141
:release => '14.04',
4242
:majrelease => '14',
4343
:lsbdistcodename => 'trusty',
44-
:packages => 'molly-guard',
44+
:packages => 'molly_guard',
4545
},
4646
'ubuntu1604' =>
4747
{ :osfamily => 'Debian',
4848
:release => '16.04',
4949
:majrelease => '16',
5050
:lsbdistcodename => 'xenial',
51-
:packages => 'molly-guard',
51+
:packages => 'molly_guard',
5252
},
5353
}
5454

@@ -92,7 +92,6 @@
9292
'owner' => 'root',
9393
'group' => 'root',
9494
'mode' => '0644',
95-
'content' => 'template(\'molly_guard/rc.erb\')',
9695
})
9796
end
9897

@@ -118,12 +117,12 @@
118117

119118
context 'when package_ensure is set to valid string <absent>' do
120119
let(:params) { { :package_ensure => 'absent' } }
121-
it { should contain_package('molly-guard').with_ensure('absent') }
120+
it { should contain_package('molly_guard').with_ensure('absent') }
122121
end
123122

124123
context 'when package_name is set to valid string <molly-guard>' do
125124
let(:params) { { :package_name => 'molly-guard' } }
126-
it { should contain_package('molly-guard').with_name('molly-guard') }
125+
it { should contain_package('molly_guard').with_name('molly-guard') }
127126
end
128127
end
129128

@@ -135,50 +134,6 @@
135134
}
136135
end
137136

138-
context 'when EL is unsupported' do
139-
let :facts do
140-
{ :osfamily => 'RedHat',
141-
:operatingsystemmajrelease => '4',
142-
}
143-
end
144-
145-
it 'should fail' do
146-
expect do
147-
should contain_class('molly-guard')
148-
end.to raise_error(Puppet::Error, /molly_guard doen't support EL\. Detected osfamily is <RedHat>/)
149-
end
150-
end
151-
152-
context 'when major release of Debian is unsupported' do
153-
let :facts do
154-
{ :osfamily => 'Debian',
155-
:operatingsystemmajrelease => '4',
156-
:lsbdistcodename => 'etch',
157-
}
158-
end
159-
160-
it 'should fail' do
161-
expect do
162-
should contain_class('molly_guard')
163-
end.to raise_error(Puppet::Error, /molly_guard supports Debian 6 \(squeeze\), 7 \(wheezy\) and 8 \(jessie\) and Ubuntu 10\.04 \(lucid\), 12\.04 \(precise\), 14.04 \(trusty\) and 16.04 \(xenial\). Detected lsbdistcodename is <etch>\./)
164-
end
165-
end
166-
167-
context 'when major release of Ubuntu is unsupported' do
168-
let :facts do
169-
{ :osfamily => 'Debian',
170-
:operatingsystemmajrelease => '8',
171-
:lsbdistcodename => 'hardy',
172-
}
173-
end
174-
175-
it 'should fail' do
176-
expect do
177-
should contain_class('molly_guard')
178-
end.to raise_error(Puppet::Error, /molly_guard supports Debian 6 \(squeeze\), 7 \(wheezy\) and 8 \(jessie\) and Ubuntu 10\.04 \(lucid\), 12\.04 \(precise\), 14.04 \(trusty\) and 16.04 \(xenial\). Detected lsbdistcodename is <hardy>\./)
179-
end
180-
end
181-
182137
context 'when osfamily is unsupported' do
183138
let :facts do
184139
{ :osfamily => 'Unsupported',

templates/rc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# rc: Managed by puppet.
22
#
3-
ALWAYS_QUERY_HOSTNAME=<%= @always_query_hostname %>
3+
ALWAYS_QUERY_HOSTNAME=<%= @always_query_hostname_bool %>

0 commit comments

Comments
 (0)