Skip to content

Commit 8bd8ddf

Browse files
committed
add diff tests for each os type
Signed-off-by: Patrick Münch <patrick.muench1111@gmail.com>
1 parent c84ec3a commit 8bd8ddf

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

controls/postgres_spec.rb

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@
6666
impact 1.0
6767
title 'Postgresql should be running'
6868
desc 'Postgresql should be running.'
69+
# describe service(postgres.service) do
70+
# it { should be_installed }
71+
# it { should be_running }
72+
# it { should be_enabled }
73+
# end
6974
case os[:name]
7075
when 'ubuntu'
7176
case os[:release]
7277
when '12.04'
73-
describe service(postgres.service) do
74-
it { should be_installed }
75-
it { should be_running }
76-
it { should be_enabled }
78+
describe command('/etc/init.d/postgresql status') do
79+
its('stdout') { should include 'online' }
80+
end
81+
when '14.04'
82+
describe command('service postgresql status') do
83+
its('stdout') { should include 'online' }
7784
end
7885
when '16.04'
7986
describe systemd_service(postgres.service) do
@@ -82,19 +89,22 @@
8289
it { should be_enabled }
8390
end
8491
end
85-
when 'redhat', 'centos', 'oracle'
92+
when 'debian'
93+
case os[:release]
94+
when /7\./
95+
describe command('/etc/init.d/postgresql status') do
96+
its('stdout') { should include 'Running' }
97+
end
98+
end
99+
when 'redhat', 'centos', 'oracle', 'fedora'
86100
case os[:release]
87101
when /6\./
88-
describe runit_service(postgres.service) do
89-
it { should be_installed }
90-
it { should be_running }
91-
it { should be_enabled }
102+
describe command('/etc/init.d/postgresql-9.4 status') do
103+
its('stdout') { should include 'running' }
92104
end
93105
when /7\./
94-
describe systemd_service(postgres.service) do
95-
it { should be_installed }
96-
it { should be_running }
97-
it { should be_enabled }
106+
describe command('ps aux | awk /\'bin\/postgres\'/ | wc -l') do
107+
its('stdout') { should include '1' }
98108
end
99109
end
100110
end
@@ -105,7 +115,7 @@
105115
title 'Use stable postgresql version'
106116
desc 'Use only community or commercially supported version of the PostgreSQL software. Do not use RC, DEVEL oder BETA versions in a production environment.'
107117
describe command('psql -V') do
108-
its('stdout') { should match(/9.[2-5]/) }
118+
its('stdout') { should match(/9.[1-5]/) }
109119
end
110120
describe command('psql -V') do
111121
its('stdout') { should_not match(/RC/) }
@@ -118,14 +128,14 @@
118128
impact 1.0
119129
title 'Run one postgresql instance per operating system'
120130
desc 'Only one postgresql database instance must be running on an operating system instance (both physical HW or virtualized).'
121-
if os[:family] == 'debian'
122-
describe processes('postgres') do
123-
its('list.length') { should eq 1 }
124-
end
125-
elsif os[:family] == 'redhat'
126-
describe processes('postmaster') do
127-
its('list.length') { should eq 1 }
128-
end
131+
if os.redhat? && os.release.include?('6.')
132+
pg_command = 'postmaster'
133+
else
134+
pg_command = 'postgres'
135+
end
136+
137+
describe processes(pg_command) do
138+
its('list.length') { should eq 1 }
129139
end
130140
end
131141

0 commit comments

Comments
 (0)