Skip to content

Commit a893b9a

Browse files
committed
Write facts as shared examples and move to Debian 11
Previously there was a lot of duplication between facts. This now stores them as shared examples in spec_helper_local.rb and also extracts them from rspec-puppet-facts where possible. Debian 8 isn't in metadata.json anymore which meant it was testing for an unsupported OS by default. It's now changed to Debian 11.
1 parent 1e43092 commit a893b9a

35 files changed

+179
-849
lines changed

spec/classes/client_spec.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
require 'spec_helper'
44

55
describe 'postgresql::client' do
6-
let :facts do
7-
{
8-
os: {
9-
family: 'Debian',
10-
name: 'Debian',
11-
release: { 'full' => '8.0', 'major' => '8' },
12-
},
13-
}
14-
end
6+
include_examples 'Debian 11'
157

168
describe 'with parameters' do
179
let :params do

spec/classes/globals_spec.rb

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,8 @@
33
require 'spec_helper'
44

55
describe 'postgresql::globals' do
6-
context 'on a debian 8' do
7-
let(:facts) do
8-
{
9-
os: {
10-
family: 'Debian',
11-
name: 'Debian',
12-
release: {
13-
full: '8.0',
14-
major: '8',
15-
},
16-
distro: { 'codename' => 'jessie' },
17-
},
18-
osfamily: 'Debian',
19-
lsbdistid: 'Debian',
20-
lsbdistcodename: 'jessie',
21-
}
22-
end
6+
context 'on a debian 11' do
7+
include_examples 'Debian 11'
238

249
describe 'with no parameters' do
2510
it 'works' do
@@ -40,17 +25,8 @@
4025
end
4126
end
4227

43-
context 'on redhat family systems' do
44-
let(:facts) do
45-
{
46-
os: {
47-
family: 'RedHat',
48-
name: 'RedHat',
49-
release: { 'full' => '7.1', 'major' => '7' },
50-
},
51-
osfamily: 'RedHat',
52-
}
53-
end
28+
context 'on redhat 7' do
29+
include_examples 'RedHat 7'
5430

5531
describe 'with no parameters' do
5632
it 'works' do

spec/classes/lib/devel_spec.rb

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
require 'spec_helper'
44

55
describe 'postgresql::lib::devel' do
6-
let :facts do
7-
{
8-
os: {
9-
family: 'Debian',
10-
name: 'Debian',
11-
release: { 'full' => '8.0', 'major' => '8' },
12-
},
13-
}
14-
end
6+
include_examples 'Debian 11'
157

168
it { is_expected.to contain_class('postgresql::lib::devel') }
179

1810
describe 'link pg_config to /usr/bin' do
1911
it {
2012
is_expected.not_to contain_file('/usr/bin/pg_config') \
2113
.with_ensure('link') \
22-
.with_target('/usr/lib/postgresql/8.4/bin/pg_config')
14+
.with_target('/usr/lib/postgresql/13/bin/pg_config')
2315
}
2416
end
2517

@@ -34,29 +26,13 @@
3426
end
3527

3628
describe 'should not link pg_config on RedHat with default version' do
37-
let(:facts) do
38-
{
39-
os: {
40-
family: 'RedHat',
41-
name: 'CentOS',
42-
release: { 'full' => '6.3', 'major' => '6' },
43-
},
44-
}
45-
end
29+
include_examples 'RedHat 6'
4630

4731
it { is_expected.not_to contain_file('/usr/bin/pg_config') }
4832
end
4933

5034
describe 'link pg_config on RedHat with non-default version' do
51-
let(:facts) do
52-
{
53-
os: {
54-
family: 'RedHat',
55-
name: 'RedHat',
56-
release: { 'full' => '6.3', 'major' => '6' },
57-
},
58-
}
59-
end
35+
include_examples 'RedHat 6'
6036
let :pre_condition do
6137
"class { '::postgresql::globals': version => '9.3' }"
6238
end
@@ -69,24 +45,15 @@
6945
end
7046

7147
describe 'on Gentoo' do
72-
let :facts do
73-
{
74-
os: {
75-
family: 'Gentoo',
76-
name: 'Gentoo',
77-
},
78-
}
79-
end
48+
include_examples 'Gentoo'
8049
let :params do
8150
{
8251
link_pg_config: false,
8352
}
8453
end
8554

8655
it 'fails to compile' do
87-
expect {
88-
is_expected.to compile
89-
}.to raise_error(%r{is not supported})
56+
is_expected.to compile.and_raise_error(%r{is not supported})
9057
end
9158
end
9259
end

spec/classes/lib/java_spec.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44

55
describe 'postgresql::lib::java' do
66
describe 'on a debian based os' do
7-
let :facts do
8-
{
9-
os: {
10-
family: 'Debian',
11-
name: 'Debian',
12-
release: { 'full' => '8.0', 'major' => '8' },
13-
},
14-
}
15-
end
7+
include_examples 'Debian 11'
168

179
it {
1810
is_expected.to contain_package('postgresql-jdbc').with(
@@ -24,15 +16,7 @@
2416
end
2517

2618
describe 'on a redhat based os' do
27-
let :facts do
28-
{
29-
os: {
30-
family: 'RedHat',
31-
name: 'RedHat',
32-
release: { 'full' => '6.4', 'major' => '6' },
33-
},
34-
}
35-
end
19+
include_examples 'RedHat 8'
3620

3721
it {
3822
is_expected.to contain_package('postgresql-jdbc').with(

spec/classes/lib/perl_spec.rb

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
require 'spec_helper'
44

55
describe 'postgresql::lib::perl' do
6-
describe 'on a redhat based os' do
7-
let :facts do
8-
{
9-
os: {
10-
family: 'RedHat',
11-
name: 'RedHat',
12-
release: { 'full' => '6.4', 'major' => '6' },
13-
},
14-
}
15-
end
6+
describe 'on redhat 8' do
7+
include_examples 'RedHat 8'
168

179
it {
1810
is_expected.to contain_package('perl-DBD-Pg').with(
@@ -22,16 +14,8 @@
2214
}
2315
end
2416

25-
describe 'on a debian based os' do
26-
let :facts do
27-
{
28-
os: {
29-
family: 'Debian',
30-
name: 'Debian',
31-
release: { 'full' => '8.0', 'major' => '8' },
32-
},
33-
}
34-
end
17+
describe 'on debian 11' do
18+
include_examples 'Debian 11'
3519

3620
it {
3721
is_expected.to contain_package('perl-DBD-Pg').with(

spec/classes/lib/pgdocs_spec.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44

55
describe 'postgresql::lib::docs' do
66
describe 'on a redhat based os' do
7-
let :facts do
8-
{
9-
os: {
10-
family: 'RedHat',
11-
name: 'RedHat',
12-
release: { 'full' => '6.4', 'major' => '6' },
13-
},
14-
}
15-
end
7+
include_examples 'RedHat 8'
168

179
it {
1810
is_expected.to contain_package('postgresql-docs').with(

spec/classes/lib/python_spec.rb

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
require 'spec_helper'
44

55
describe 'postgresql::lib::python' do
6-
describe 'on a redhat based os' do
7-
let :facts do
8-
{
9-
os: {
10-
family: 'RedHat',
11-
name: 'RedHat',
12-
release: { 'full' => '6.4', 'major' => '6' },
13-
},
14-
}
15-
end
6+
describe 'on redhat 7' do
7+
include_examples 'RedHat 7'
168

179
it {
1810
is_expected.to contain_package('python-psycopg2').with(
@@ -22,16 +14,8 @@
2214
}
2315
end
2416

25-
describe 'on a redhat based os with python 3' do
26-
let :facts do
27-
{
28-
os: {
29-
family: 'RedHat',
30-
name: 'RedHat',
31-
release: { 'full' => '8.2', 'major' => '8' },
32-
},
33-
}
34-
end
17+
describe 'on redhat 8' do
18+
include_examples 'RedHat 8'
3519

3620
it {
3721
is_expected.to contain_package('python-psycopg2').with(
@@ -41,16 +25,8 @@
4125
}
4226
end
4327

44-
describe 'on a debian based os' do
45-
let :facts do
46-
{
47-
os: {
48-
family: 'Debian',
49-
name: 'Debian',
50-
release: { 'full' => '8.0', 'major' => '8' },
51-
},
52-
}
53-
end
28+
describe 'on debian 11' do
29+
include_examples 'Debian 11'
5430

5531
it {
5632
is_expected.to contain_package('python-psycopg2').with(

spec/classes/params_spec.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
require 'spec_helper'
44

55
describe 'postgresql::params' do
6-
let :facts do
7-
{
8-
os: {
9-
family: 'Debian',
10-
name: 'Debian',
11-
release: { 'full' => '8.0', 'major' => '8' },
12-
},
13-
}
14-
end
6+
on_supported_os.each do |os, os_facts|
7+
context "on #{os}" do
8+
let(:facts) { os_facts }
159

16-
it { is_expected.to contain_class('postgresql::params') }
10+
it { is_expected.to contain_class('postgresql::params') }
11+
end
12+
end
1713
end

spec/classes/repo_spec.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33
require 'spec_helper'
44

55
describe 'postgresql::repo' do
6-
let :facts do
7-
{
8-
os: {
9-
name: 'Debian',
10-
family: 'Debian',
11-
release: {
12-
full: '8.0',
13-
major: '8',
14-
},
15-
distro: { 'codename' => 'jessie' },
16-
},
17-
osfamily: 'Debian',
18-
lsbdistid: 'Debian',
19-
lsbdistcodename: 'jessie',
20-
}
21-
end
6+
include_examples 'Debian 11'
227

238
describe 'with no parameters' do
249
it 'instantiates apt_postgresql_org class' do

0 commit comments

Comments
 (0)