diff --git a/spec/unit/classes/server/config_spec.rb b/spec/unit/classes/server/config_spec.rb index 1e413b0..a1ce20e 100644 --- a/spec/unit/classes/server/config_spec.rb +++ b/spec/unit/classes/server/config_spec.rb @@ -1,387 +1,387 @@ # frozen_string_literal: true require 'spec_helper' describe 'postgresql::server::config', type: :class do let(:pre_condition) do 'class { postgresql::server: manage_selinux => true }' end describe 'on RedHat 7' do let(:facts) do { kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, os: { 'architecture' => 'x86_64', 'family' => 'RedHat', 'hardware' => 'x86_64', 'name' => 'CentOS', 'release' => { 'full' => '7.9.2009', 'major' => '7', 'minor' => '9', }, selinux: { 'enabled' => true }, }, operatingsystemrelease: '7.9.2009', service_provider: 'systemd', } 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') .that_comes_before('Postgresql::Server::Config_entry[port]') .that_requires('Package[policycoreutils-python]') end it 'removes the old systemd-override file' do is_expected.to contain_file('old-systemd-override') .with(ensure: 'absent', path: '/etc/systemd/system/postgresql.service') end it 'has the correct systemd-override drop file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql.service.d/postgresql.conf', owner: 'root', group: 'root' ) .that_requires('File[systemd-conf-dir]') end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') \ .with_content(%r{(?!^.include)}) end context 'RHEL 7 host with Puppet 5' do let(:facts) do { kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, os: { 'architecture' => 'x86_64', 'family' => 'RedHat', 'hardware' => 'x86_64', 'name' => 'CentOS', 'release' => { 'full' => '7.9.2009', 'major' => '7', 'minor' => '9', }, selinux: { 'enabled' => true }, }, operatingsystemrelease: '7.9.2009', puppetversion: '5.0.1', service_provider: 'systemd', } end it 'has systemctl restart command' do is_expected.to contain_exec('restart-systemd').with( command: 'systemctl daemon-reload', refreshonly: true, path: '/bin:/usr/bin:/usr/local/bin', ) end end describe 'with manage_package_repo => true and a version' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': manage_package_repo => true, version => '9.4', }-> class { 'postgresql::server': } EOS end it 'has the correct systemd-override file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql-9.4.service.d/postgresql-9.4.conf', owner: 'root', group: 'root' ) end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') .without_content(%r{\.include}) end end end describe 'on Redhat 8' do let(:facts) do { kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, os: { 'architecture' => 'x86_64', 'family' => 'RedHat', 'hardware' => 'x86_64', 'name' => 'RedHat', 'release' => { 'full' => '8.2.2004', 'major' => '8', 'minor' => '2', }, selinux: { 'enabled' => true }, }, operatingsystem: 'RedHat', operatingsystemrelease: '8.2.2004', service_provider: 'systemd', } 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') .that_comes_before('Postgresql::Server::Config_entry[port]') .that_requires('Package[policycoreutils-python-utils]') end it 'removes the old systemd-override file' do is_expected.to contain_file('old-systemd-override') .with(ensure: 'absent', path: '/etc/systemd/system/postgresql.service') end it 'has the correct systemd-override drop file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql.service.d/postgresql.conf', owner: 'root', group: 'root' ) .that_requires('File[systemd-conf-dir]') end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') .without_content(%r{\.include}) end describe 'with manage_package_repo => true and a version' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': manage_package_repo => true, version => '9.4', }-> class { 'postgresql::server': } EOS end it 'has the correct systemd-override file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql-9.4.service.d/postgresql-9.4.conf', owner: 'root', group: 'root' ) end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') .without_content(%r{\.include}) end end end describe 'on Fedora 33' do let(:facts) do { kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, os: { 'architecture' => 'x86_64', 'family' => 'RedHat', 'hardware' => 'x86_64', 'name' => 'Fedora', 'release' => { 'full' => '33', 'major' => '33', 'minor' => '33', }, selinux: { 'enabled' => true }, }, operatingsystem: 'Fedora', operatingsystemrelease: '33', service_provider: 'systemd', } 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') .that_comes_before('Postgresql::Server::Config_entry[port]') .that_requires('Package[policycoreutils-python-utils]') end it 'removes the old systemd-override file' do is_expected.to contain_file('old-systemd-override') .with(ensure: 'absent', path: '/etc/systemd/system/postgresql.service') end it 'has the correct systemd-override drop file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql.service.d/postgresql.conf', owner: 'root', group: 'root' ) .that_requires('File[systemd-conf-dir]') end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') .without_content(%r{\.include}) end describe 'with manage_package_repo => true and a version' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': manage_package_repo => true, version => '13', }-> class { 'postgresql::server': } EOS end it 'has the correct systemd-override file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql-13.service.d/postgresql-13.conf', owner: 'root', group: 'root' ) end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') .without_content(%r{\.include}) end end end describe 'on Amazon' do let :facts do { os: { family: 'RedHat', name: 'Amazon', release: { 'full' => '1.0', 'major' => '1', }, selinux: { 'enabled' => true }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, } 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') .that_comes_before('Postgresql::Server::Config_entry[port]') .that_requires('Package[policycoreutils]') end end describe 'with managed pg_hba_conf and ipv4acls' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': version => '9.5', }-> class { 'postgresql::server': manage_pg_hba_conf => true, ipv4acls => [ 'hostnossl all all 0.0.0.0/0 reject', 'hostssl all all 0.0.0.0/0 md5' ] } EOS end let(:facts) do { os: { family: 'RedHat', name: 'CentOS', release: { 'full' => '7.9.2009', 'major' => '7', 'minor' => '9', }, selinux: { 'enabled' => true }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: true, service_provider: 'systemd', } end it 'has hba rule default' do is_expected.to contain_postgresql__server__pg_hba_rule('local access as postgres user') end it 'has hba rule ipv4acls' do is_expected.to contain_postgresql__server__pg_hba_rule('postgresql class generated rule ipv4acls 0') end end describe 'on Gentoo' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': version => '9.5', }-> class { 'postgresql::server': } EOS end let(:facts) do { os: { family: 'Gentoo', name: 'Gentoo', release: { 'full' => 'unused', 'major' => 'unused', }, selinux: { 'enabled' => true }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', selinux: false, service_provider: 'systemd', } end it 'does not have SELinux port defined' do is_expected.not_to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432') end it 'removes the old systemd-override file' do is_expected.to contain_file('old-systemd-override') .with(ensure: 'absent', path: '/etc/systemd/system/postgresql-9.5.service') end it 'has the correct systemd-override drop file' do is_expected.to contain_file('systemd-override').with( ensure: 'file', path: '/etc/systemd/system/postgresql-9.5.service.d/postgresql-9.5.conf', owner: 'root', group: 'root' ) end it 'has the correct systemd-override file #regex' do is_expected.to contain_file('systemd-override') \ .with_content(%r{(?!^.include)}) end end end diff --git a/spec/unit/defines/server/default_privileges_spec.rb b/spec/unit/defines/server/default_privileges_spec.rb index df8abf5..9b47538 100644 --- a/spec/unit/defines/server/default_privileges_spec.rb +++ b/spec/unit/defines/server/default_privileges_spec.rb @@ -1,288 +1,275 @@ # frozen_string_literal: true require 'spec_helper' -require 'spec_helper_acceptance' describe 'postgresql::server::default_privileges', type: :define do let :facts do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '9.0', 'major' => '9' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end context 'with unsupported PostgreSQL version' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '8.0', 'major' => '8' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', } end let :pre_condition do "class {'postgresql::server': }" end it { is_expected.to compile.and_raise_error(%r{Default_privileges is only useable with PostgreSQL >= 9.6}m) } end context 'case insensitive object_type and privilege match' do let :params do { db: 'test', role: 'test', privilege: 'aLl', object_type: 'TaBlEs', } end let :pre_condition do "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 context 'invalid object_type' do context 'tables' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'wrong_type', } end let :pre_condition do "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 context 'valid object_type' do context 'supported privilege' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', } end let :pre_condition do "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 context 'unsupported privilege' do let :params do { db: 'test', role: 'test', privilege: 'wrong_privilege', object_type: 'tables', } end let :pre_condition do "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 context 'with specific db connection settings - default port' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6' }, } end let :pre_condition do "class {'postgresql::server':}" 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_psql('default_privileges:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6').with_port(5432) } end context 'with specific db connection settings - including port' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6', 'PGPORT' => '1234' }, } end let :pre_condition do "class {'postgresql::server':}" 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_psql('default_privileges:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6', 'PGPORT' => '1234') } end context 'with specific db connection settings - port overriden by explicit parameter' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6', 'PGPORT' => '1234' }, port: 5678, } end let :pre_condition do "class {'postgresql::server':}" 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_psql('default_privileges:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.6', 'PGPORT' => '1234').with_port('5678') } end context 'with specific schema name' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', schema: 'my_schema' } end let :pre_condition do "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 context 'with a role defined' do let :params do { db: 'test', role: 'test', privilege: 'all', object_type: 'tables', } end let :pre_condition do <<-EOS class {'postgresql::server':} postgresql::server::role { 'test': } 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 context 'standalone not managing server' do let :params do { db: 'test', role: 'test', privilege: 'execute', object_type: 'functions', group: 'postgresql', psql_path: '/usr/bin', psql_user: 'postgres', psql_db: 'db', port: 1542, connect_settings: { 'DBVERSION' => '9.6' }, } end it { is_expected.to compile.with_all_deps } it { is_expected.not_to contain_class('postgresql::server') } end end diff --git a/spec/unit/defines/server/extension_spec.rb b/spec/unit/defines/server/extension_spec.rb index 6c88960..0489998 100644 --- a/spec/unit/defines/server/extension_spec.rb +++ b/spec/unit/defines/server/extension_spec.rb @@ -1,275 +1,275 @@ # frozen_string_literal: true require 'spec_helper' describe 'postgresql::server::extension', type: :define do # rubocop:disable RSpec/MultipleDescribes let :pre_condition do "class { 'postgresql::server': } postgresql::server::database { 'template_postgis': template => 'template1', }" end let :facts do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '8.0', 'major' => '8' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'postgis' } let(:params) do { database: 'template_postgis', } end context 'with mandatory arguments only' do it { is_expected.to contain_postgresql_psql('template_postgis: CREATE EXTENSION "postgis"') .with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } end context 'when schema is specified' do let(:params) do super().merge(schema: 'pg_catalog') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" SET SCHEMA "pg_catalog"') } end context 'when setting package name' do let(:params) do super().merge(package_name: 'postgis') end 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 context 'when ensuring absence' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis') end it { is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"') .with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } it { is_expected.to contain_package('postgis').with(ensure: 'absent', name: 'postgis') } context 'when keeping package installed' do let(:params) do super().merge(package_ensure: 'present') end it { is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"') .with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } 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 context 'when extension version is specified' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis', version: '99.99.99') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE TO \'99.99.99\'') .with(db: 'template_postgis', unless: "SELECT 1 FROM pg_extension WHERE extname='postgis' AND extversion='99.99.99'").that_requires('Postgresql::Server::Database[template_postgis]') } end context 'when extension version is latest' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis', version: 'latest') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE') .with(db: 'template_postgis', unless: "SELECT 1 FROM pg_available_extensions WHERE name = 'postgis' AND default_version = installed_version").that_requires('Postgresql::Server::Database[template_postgis]') } end end describe 'postgresql::server::extension', type: :define do let :pre_condition do "class { 'postgresql::server': } postgresql::server::database { 'template_postgis2': template => 'template1', }" end let :facts do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '6.0', 'major' => '6' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'postgis_db2' } let(:params) do { database: 'template_postgis2', extension: 'postgis', } end it { is_expected.to contain_file('/var/lib/postgresql/8.4/main') } # FIXME: be more precise it { is_expected.to contain_concat('/etc/postgresql/8.4/main/pg_hba.conf') } # FIXME: be more precise it { is_expected.to contain_concat('/etc/postgresql/8.4/main/pg_ident.conf') } # FIXME: be more precise context 'with mandatory arguments only' do it { is_expected.to contain_postgresql_psql('template_postgis2: CREATE EXTENSION "postgis"') .with(db: 'template_postgis2', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis2]') } end end describe 'postgresql::server::extension', type: :define do let :facts do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '6.0', 'major' => '6' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'pg_repack' } let(:params) do { database: 'postgres', extension: 'pg_repack', } end context 'without including postgresql::server' do let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with(db: 'postgres', command: 'CREATE EXTENSION "pg_repack"') } end context 'default port' do let :params do { database: 'postgres', extension: 'pg_repack', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"').with_port('5432') } end context 'port overriden by explicit parameter' do let :params do { database: 'postgres', extension: 'pg_repack', port: 1234, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"').with_port('1234') } end context 'with specific db connection settings' do let :params do { database: 'postgres', extension: 'pg_repack', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' }, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') .with_port(nil) } end context 'with specific db connection settings - port overriden by explicit parameter' do let :params do { database: 'postgres', extension: 'pg_repack', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' }, port: 5678, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') .with_port('5678') } end end