From c8303fd1791ac66633429be0682b7a583b16d391 Mon Sep 17 00:00:00 2001 From: adrianiurca Date: Wed, 11 Aug 2021 15:57:07 +0300 Subject: [PATCH 1/2] Reflect change of default in ensure_packages https://github.com/puppetlabs/puppetlabs-stdlib/commit/77a9c07c9e64f03b12a4d8068941609f44829c8b changed the default for ensure_packages() in stdlib. This change updates the tests to match that default change. --- spec/unit/classes/server/config_spec.rb | 8 ++++---- spec/unit/defines/server/extension_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/unit/classes/server/config_spec.rb b/spec/unit/classes/server/config_spec.rb index 1e413b08d2..a1ce20efab 100644 --- a/spec/unit/classes/server/config_spec.rb +++ b/spec/unit/classes/server/config_spec.rb @@ -32,7 +32,7 @@ end it 'has SELinux port defined' do - is_expected.to contain_package('policycoreutils-python') .with(ensure: 'present') + is_expected.to contain_package('policycoreutils-python').with(ensure: 'installed') is_expected.to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432') .with(unless: '/usr/sbin/semanage port -l | grep -qw 5432') @@ -141,7 +141,7 @@ class { 'postgresql::server': } end it 'has SELinux port defined' do - is_expected.to contain_package('policycoreutils-python-utils') .with(ensure: 'present') + is_expected.to contain_package('policycoreutils-python-utils').with(ensure: 'installed') is_expected.to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432') .with(unless: '/usr/sbin/semanage port -l | grep -qw 5432') @@ -214,7 +214,7 @@ class { 'postgresql::server': } end it 'has SELinux port defined' do - is_expected.to contain_package('policycoreutils-python-utils') .with(ensure: 'present') + is_expected.to contain_package('policycoreutils-python-utils').with(ensure: 'installed') is_expected.to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432') .with(unless: '/usr/sbin/semanage port -l | grep -qw 5432') @@ -282,7 +282,7 @@ class { 'postgresql::server': } end it 'has SELinux port defined' do - is_expected.to contain_package('policycoreutils') .with(ensure: 'present') + is_expected.to contain_package('policycoreutils').with(ensure: 'installed') is_expected.to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432') .with(unless: '/usr/sbin/semanage port -l | grep -qw 5432') diff --git a/spec/unit/defines/server/extension_spec.rb b/spec/unit/defines/server/extension_spec.rb index 6c889601c0..04899982cd 100644 --- a/spec/unit/defines/server/extension_spec.rb +++ b/spec/unit/defines/server/extension_spec.rb @@ -54,7 +54,7 @@ it { is_expected.to contain_package('postgis') - .with(ensure: 'present', name: 'postgis').that_comes_before('Postgresql_psql[template_postgis: CREATE EXTENSION "postgis"]') + .with(ensure: 'installed', name: 'postgis').that_comes_before('Postgresql_psql[template_postgis: CREATE EXTENSION "postgis"]') } end @@ -86,7 +86,7 @@ it { is_expected.to contain_package('postgis') - .with(ensure: 'present', name: 'postgis').that_requires('Postgresql_psql[template_postgis: DROP EXTENSION "postgis"]') + .with(ensure: 'installed', name: 'postgis').that_requires('Postgresql_psql[template_postgis: DROP EXTENSION "postgis"]') } end end From fc01e83f5a62dfe673e6f8428c6aa6bbee4e059f Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sun, 15 Aug 2021 20:28:32 +0200 Subject: [PATCH 2/2] Remove use of spec_helper_acceptance in unit tests In c96b073b40b7d48ac5c7a4e68796b4f87ba65abd the acceptance helper was included in the unit tests. This should never happen and breaks the tests. It appears it was included to have a postgresql_version but that should be defined in let blocks. The acceptance helper only works if there is an actual target machine. Fixes: c96b073b40b7d48ac5c7a4e68796b4f87ba65abd --- .../defines/server/default_privileges_spec.rb | 71 ++++++++----------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/spec/unit/defines/server/default_privileges_spec.rb b/spec/unit/defines/server/default_privileges_spec.rb index df8abf5b01..9b47538159 100644 --- a/spec/unit/defines/server/default_privileges_spec.rb +++ b/spec/unit/defines/server/default_privileges_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'spec_helper_acceptance' describe 'postgresql::server::default_privileges', type: :define do let :facts do @@ -65,13 +64,11 @@ "class {'postgresql::server':}" end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_postgresql__server__default_privileges('test') } - it do - is_expected.to contain_postgresql_psql('default_privileges:test') - .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"') - end + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_postgresql__server__default_privileges('test') } + it do + is_expected.to contain_postgresql_psql('default_privileges:test') + .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"') end end @@ -90,9 +87,7 @@ "class {'postgresql::server':}" end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.and_raise_error(%r{parameter 'object_type' expects a match for Pattern}) } - end + it { is_expected.to compile.and_raise_error(%r{parameter 'object_type' expects a match for Pattern}) } end end @@ -111,16 +106,14 @@ "class {'postgresql::server':}" end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_postgresql__server__default_privileges('test') } - it do - # rubocop:disable Layout/LineLength - is_expected.to contain_postgresql_psql('default_privileges:test') - .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"') - .with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')") - # rubocop:enable Layout/LineLength - end + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_postgresql__server__default_privileges('test') } + it do + # rubocop:disable Layout/LineLength + is_expected.to contain_postgresql_psql('default_privileges:test') + .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"') + .with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')") + # rubocop:enable Layout/LineLength end end @@ -138,9 +131,7 @@ "class {'postgresql::server':}" end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.and_raise_error(%r{Illegal value for \$privilege parameter}) } - end + it { is_expected.to compile.and_raise_error(%r{Illegal value for \$privilege parameter}) } end end @@ -225,16 +216,14 @@ "class {'postgresql::server':}" end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_postgresql__server__default_privileges('test') } - it do - # rubocop:disable Layout/LineLength - is_expected.to contain_postgresql_psql('default_privileges:test') - .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema GRANT ALL ON TABLES TO "test"') - .with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')") - # rubocop:enable Layout/LineLength - end + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_postgresql__server__default_privileges('test') } + it do + # rubocop:disable Layout/LineLength + is_expected.to contain_postgresql_psql('default_privileges:test') + .with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema GRANT ALL ON TABLES TO "test"') + .with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')") + # rubocop:enable Layout/LineLength end end @@ -255,14 +244,12 @@ class {'postgresql::server':} EOS end - if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_postgresql__server__default_privileges('test') } - it { is_expected.to contain_postgresql__server__role('test') } - it do - is_expected.to contain_postgresql_psql('default_privileges:test') \ - .that_requires(['Service[postgresqld]', 'Postgresql::Server::Role[test]']) - end + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_postgresql__server__default_privileges('test') } + it { is_expected.to contain_postgresql__server__role('test') } + it do + is_expected.to contain_postgresql_psql('default_privileges:test') \ + .that_requires(['Service[postgresqld]', 'Postgresql::Server::Role[test]']) end end