From 58ac122d5059bb2ec3532ed47f0c6ed73562f367 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 25 Apr 2019 03:01:31 +0100 Subject: [PATCH] test(inspec): replace `serverspec` with `inspec` tests --- .../default/controls/command_spec.rb | 7 ++++++ .../default/controls/config_spec.rb | 10 ++++++++ .../default/controls/services_spec.rb | 13 +++++++++++ test/integration/default/inspec.yml | 11 +++++++++ .../default/serverspec/postgres_spec.rb | 23 ------------------- 5 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 test/integration/default/controls/command_spec.rb create mode 100644 test/integration/default/controls/config_spec.rb create mode 100644 test/integration/default/controls/services_spec.rb create mode 100644 test/integration/default/inspec.yml delete mode 100644 test/integration/default/serverspec/postgres_spec.rb diff --git a/test/integration/default/controls/command_spec.rb b/test/integration/default/controls/command_spec.rb new file mode 100644 index 0000000..9b1b8cb --- /dev/null +++ b/test/integration/default/controls/command_spec.rb @@ -0,0 +1,7 @@ +control 'Postgres command' do + title 'should match desired lines' + + describe command(%q{su - postgres -c 'psql -qtc "\l+ db2"'}) do + its(:stdout) { should match(/db2.*remoteUser.*UTF8.*en_US\.UTF-8.*en_US\.UTF-8.*my_space/) } + end +end diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb new file mode 100644 index 0000000..dc61924 --- /dev/null +++ b/test/integration/default/controls/config_spec.rb @@ -0,0 +1,10 @@ +control 'Postgres configuration' do + title 'should include the directory' + + describe file('/srv/my_tablespace') do + it { should be_directory } + it { should be_owned_by 'postgres' } + it { should be_grouped_into 'postgres' } + its('mode') { should cmp '0700' } + end +end diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb new file mode 100644 index 0000000..f0e9dd5 --- /dev/null +++ b/test/integration/default/controls/services_spec.rb @@ -0,0 +1,13 @@ +control 'Postgres service' do + impact 0.5 + title 'should be running and enabled' + + describe service('postgresql') do + it { should be_enabled } + it { should be_running } + end + + describe port(5432) do + it { should be_listening } + end +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml new file mode 100644 index 0000000..4e5595b --- /dev/null +++ b/test/integration/default/inspec.yml @@ -0,0 +1,11 @@ +name: postgres +title: Postgres Formula +maintainer: Your Name +license: Apache-2.0 +summary: Verify that the postgres formula is setup and configured correctly +supports: + - os-name: debian + - os-name: ubuntu + - os-name: centos + - os-name: fedora + - os-name: opensuse diff --git a/test/integration/default/serverspec/postgres_spec.rb b/test/integration/default/serverspec/postgres_spec.rb deleted file mode 100644 index 768e62f..0000000 --- a/test/integration/default/serverspec/postgres_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'serverspec' - -set :backend, :exec - -describe service('postgresql') do - it { should be_enabled } - it { should be_running } -end - -describe port('5432') do - it { should be_listening } -end - -describe file('/srv/my_tablespace') do - it { should be_directory } - it { should be_mode 700 } - it { should be_owned_by 'postgres' } - it { should be_grouped_into 'postgres' } -end - -describe command(%q{su - postgres -c 'psql -qtc "\l+ db2"'}) do - its(:stdout) { should match(/db2.*remoteUser.*UTF8.*en_US\.UTF-8.*en_US\.UTF-8.*my_space/) } -end