From e11623da6dc6b5b680da265f5478f69682501acd Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sun, 3 Nov 2019 04:34:39 +0000 Subject: [PATCH] test(inspec): provide tests for the repo package and config --- epel/init.sls | 5 ++++ .../default/controls/config_spec.rb | 25 ++++++++++++++++ .../default/controls/packages_spec.rb | 30 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 test/integration/default/controls/config_spec.rb create mode 100644 test/integration/default/controls/packages_spec.rb diff --git a/epel/init.sls b/epel/init.sls index 6a2587d..5c9df40 100644 --- a/epel/init.sls +++ b/epel/init.sls @@ -8,6 +8,11 @@ install_pubkey_epel: - name: /etc/pki/rpm-gpg/{{ epel.key_name }} - source: {{ epel.key }} - source_hash: {{ epel.key_hash }} + cmd.run: + - name: | + cat /etc/pki/rpm-gpg/{{ epel.key_name }} + - require: + - file: install_pubkey_epel epel_release: pkg.installed: diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb new file mode 100644 index 0000000..48b8768 --- /dev/null +++ b/test/integration/default/controls/config_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +control 'epel repo configuration' do + title 'should match desired lines' + + epel_version = + case platform[:name] + when 'amazon' + case platform[:release] + when '2' + '7' + when '2018.03' + '6' + end + when 'centos' + platform[:release][0] + end + + describe file("/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-#{epel_version}") do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + end +end diff --git a/test/integration/default/controls/packages_spec.rb b/test/integration/default/controls/packages_spec.rb new file mode 100644 index 0000000..bac42eb --- /dev/null +++ b/test/integration/default/controls/packages_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +control 'epel package' do + title 'should be installed' + + pkg = 'epel-release' + version = + case platform[:name] + when 'amazon' + case platform[:release] + when '2' + '7-12' + when '2018.03' + '6-8' + end + when 'centos' + if platform[:release].start_with?('8') + '8-7.el8' + elsif platform[:release].start_with?('7') + '7-12' + elsif platform[:release].start_with?('6') + '6-8' + end + end + + describe package(pkg) do + it { should be_installed } + its('version') { should eq version } + end +end