Skip to content

Commit

Permalink
test(inspec): move common controls to the share profile
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Jul 20, 2021
1 parent 27473b9 commit 2214096
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/integration/default/controls/services_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# frozen_string_literal: true

# Overide by Platform
service_name = 'postgresql'
pg_port = 5432
if (platform[:name] == 'centos') && platform[:release].start_with?('6')
service_name = 'postgresql-9.6'
elsif (platform[:family] == 'debian') || (platform[:family] == 'suse')
pg_port = 5433
end

pg_port =
case platform[:family]
when 'debian', 'suse'
5433
else
5432
end

control 'Postgres service' do
impact 0.5
title 'should be running and enabled'
title 'should be installed, enabled and running'

describe service(service_name) do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
Expand Down
13 changes: 13 additions & 0 deletions test/integration/default/controls/share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# https://docs.chef.io/inspec/profiles/#including-all-controls-from-a-profile
# Could use `include_controls` in this scenario
# include_controls 'share'

# https://docs.chef.io/inspec/profiles/#selectively-including-controls-from-a-profile
# However, using `require_controls` for more clarity
require_controls 'share' do
control 'Postgres command'
control 'Postgres configuration'
# control 'Postgres service'
end
37 changes: 37 additions & 0 deletions test/integration/repo/controls/services_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

service_name =
case platform[:family]
when 'redhat', 'fedora', 'suse'
case system.platform[:release]
when 'tumbleweed'
'postgresql'
else
'postgresql-13'
end
else
'postgresql'
end

pg_port =
case platform[:family]
when 'debian', 'suse'
5433
else
5432
end

control 'Postgres service' do
impact 0.5
title 'should be installed, enabled and running'

describe service(service_name) do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end

describe port(pg_port) do
it { should be_listening }
end
end
13 changes: 13 additions & 0 deletions test/integration/repo/controls/share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# https://docs.chef.io/inspec/profiles/#including-all-controls-from-a-profile
# Could use `include_controls` in this scenario
# include_controls 'share'

# https://docs.chef.io/inspec/profiles/#selectively-including-controls-from-a-profile
# However, using `require_controls` for more clarity
require_controls 'share' do
control 'Postgres command'
control 'Postgres configuration'
# control 'Postgres service'
end

0 comments on commit 2214096

Please sign in to comment.