From 221409636290444aa06ef9e59fd324b94412a635 Mon Sep 17 00:00:00 2001 From: Imran Iqbal <iqbalmy@hotmail.com> Date: Tue, 20 Jul 2021 18:01:37 +0100 Subject: [PATCH] test(inspec): move common controls to the `share` profile --- .../default/controls/services_spec.rb | 18 +++++---- test/integration/default/controls/share.rb | 13 +++++++ .../repo/controls/services_spec.rb | 37 +++++++++++++++++++ test/integration/repo/controls/share.rb | 13 +++++++ .../controls/command_spec.rb | 0 .../controls/config_spec.rb | 0 6 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 test/integration/default/controls/share.rb create mode 100644 test/integration/repo/controls/services_spec.rb create mode 100644 test/integration/repo/controls/share.rb rename test/integration/{default => share}/controls/command_spec.rb (100%) rename test/integration/{default => share}/controls/config_spec.rb (100%) diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb index 5dfd78e..2c3d6e1 100644 --- a/test/integration/default/controls/services_spec.rb +++ b/test/integration/default/controls/services_spec.rb @@ -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 diff --git a/test/integration/default/controls/share.rb b/test/integration/default/controls/share.rb new file mode 100644 index 0000000..362f11c --- /dev/null +++ b/test/integration/default/controls/share.rb @@ -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 diff --git a/test/integration/repo/controls/services_spec.rb b/test/integration/repo/controls/services_spec.rb new file mode 100644 index 0000000..e1927db --- /dev/null +++ b/test/integration/repo/controls/services_spec.rb @@ -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 diff --git a/test/integration/repo/controls/share.rb b/test/integration/repo/controls/share.rb new file mode 100644 index 0000000..362f11c --- /dev/null +++ b/test/integration/repo/controls/share.rb @@ -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 diff --git a/test/integration/default/controls/command_spec.rb b/test/integration/share/controls/command_spec.rb similarity index 100% rename from test/integration/default/controls/command_spec.rb rename to test/integration/share/controls/command_spec.rb diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/share/controls/config_spec.rb similarity index 100% rename from test/integration/default/controls/config_spec.rb rename to test/integration/share/controls/config_spec.rb -- GitLab