diff --git a/metadata.json b/metadata.json index d1eb699..be8530f 100644 --- a/metadata.json +++ b/metadata.json @@ -1,82 +1,80 @@ { "name": "puppetlabs-postgresql", "version": "5.4.0", "author": "Inkling/Puppet Labs", "summary": "Offers support for basic management of PostgreSQL databases.", "license": "Apache-2.0", "source": "git://github.com/puppetlabs/puppetlabs-postgresql.git", "project_page": "https://github.com/puppetlabs/puppetlabs-postgresql", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.13.1 < 5.0.0" }, { "name": "puppetlabs/apt", "version_requirement": ">= 2.0.0 < 5.0.0" }, { "name": "puppetlabs/concat", "version_requirement": ">= 1.1.0 < 5.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ - "5", "6", "7" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "7", "8", "9" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "14.04", "16.04" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 4.7.0 < 6.0.0" } ], "pdk-version": "1.5.0", "template-url": "https://github.com/puppetlabs/pdk-templates", "template-ref": "heads/master-0-g34e3266" } diff --git a/spec/unit/classes/client_spec.rb b/spec/unit/classes/client_spec.rb index 0ecdef8..b28d992 100644 --- a/spec/unit/classes/client_spec.rb +++ b/spec/unit/classes/client_spec.rb @@ -1,53 +1,53 @@ require 'spec_helper' describe 'postgresql::client', type: :class do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end describe 'with parameters' do let :params do { validcon_script_path: '/opt/bin/my-validate-con.sh', package_ensure: 'absent', package_name: 'mypackage', file_ensure: 'file', } end it 'modifies package' do is_expected.to contain_package('postgresql-client').with(ensure: 'absent', name: 'mypackage', tag: 'postgresql') end it 'has specified validate connexion' do is_expected.to contain_file('/opt/bin/my-validate-con.sh').with(ensure: 'file', owner: 0, group: 0, mode: '0755') end end describe 'with no parameters' do it 'creates package with postgresql tag' do is_expected.to contain_package('postgresql-client').with(tag: 'postgresql') end end describe 'with client package name explicitly set undef' do let :params do { package_name: 'UNSET', } end it 'does not manage postgresql-client package' do is_expected.not_to contain_package('postgresql-client') end end end diff --git a/spec/unit/classes/globals_spec.rb b/spec/unit/classes/globals_spec.rb index e3d87ce..a5f4759 100644 --- a/spec/unit/classes/globals_spec.rb +++ b/spec/unit/classes/globals_spec.rb @@ -1,97 +1,97 @@ require 'spec_helper' describe 'postgresql::globals', type: :class do - context 'on a debian 6' do + context 'on a debian 8' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - full: '6.0', - major: '6', + full: '8.0', + major: '8', }, }, osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', lsbdistid: 'Debian', - lsbdistcodename: 'squeeze', + lsbdistcodename: 'jessie', } end describe 'with no parameters' do it 'works' do is_expected.to contain_class('postgresql::globals') end end describe 'manage_package_repo => true' do let(:params) do { manage_package_repo: true, } end it 'pulls in class postgresql::repo' do is_expected.to contain_class('postgresql::repo') end end end context 'on redhat family systems' do let(:facts) do { osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '7.1', } end describe 'with no parameters' do it 'works' do is_expected.to contain_class('postgresql::globals') end end describe 'manage_package_repo on RHEL => true' do let(:params) do { manage_package_repo: true, repo_proxy: 'http://proxy-server:8080', } end it 'pulls in class postgresql::repo' do is_expected.to contain_class('postgresql::repo') end it do is_expected.to contain_yumrepo('yum.postgresql.org').with( 'enabled' => '1', 'proxy' => 'http://proxy-server:8080', ) end end describe 'repo_baseurl on RHEL => mirror.localrepo.com' do let(:params) do { manage_package_repo: true, repo_baseurl: 'http://mirror.localrepo.com', } end it 'pulls in class postgresql::repo' do is_expected.to contain_class('postgresql::repo') end it do is_expected.to contain_yumrepo('yum.postgresql.org').with( 'enabled' => '1', 'baseurl' => 'http://mirror.localrepo.com', ) end end end end diff --git a/spec/unit/classes/lib/devel_spec.rb b/spec/unit/classes/lib/devel_spec.rb index 835bf51..06b4cd7 100644 --- a/spec/unit/classes/lib/devel_spec.rb +++ b/spec/unit/classes/lib/devel_spec.rb @@ -1,84 +1,84 @@ require 'spec_helper' describe 'postgresql::lib::devel', type: :class do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end it { is_expected.to contain_class('postgresql::lib::devel') } describe 'link pg_config to /usr/bin' do it { is_expected.not_to contain_file('/usr/bin/pg_config') \ .with_ensure('link') \ .with_target('/usr/lib/postgresql/8.4/bin/pg_config') } end describe 'disable link_pg_config' do let(:params) do { link_pg_config: false, } end it { is_expected.not_to contain_file('/usr/bin/pg_config') } end describe 'should not link pg_config on RedHat with default version' do let(:facts) do { osfamily: 'RedHat', operatingsystem: 'CentOS', operatingsystemrelease: '6.3', operatingsystemmajrelease: '6', } end it { is_expected.not_to contain_file('/usr/bin/pg_config') } end describe 'link pg_config on RedHat with non-default version' do let(:facts) do { osfamily: 'RedHat', operatingsystem: 'CentOS', operatingsystemrelease: '6.3', operatingsystemmajrelease: '6', } end let :pre_condition do "class { '::postgresql::globals': version => '9.3' }" end it { is_expected.to contain_file('/usr/bin/pg_config') \ .with_ensure('link') \ .with_target('/usr/pgsql-9.3/bin/pg_config') } end describe 'on Gentoo' do let :facts do { osfamily: 'Gentoo', operatingsystem: 'Gentoo', } end let :params do { link_pg_config: false, } end it 'fails to compile' do expect { is_expected.to compile }.to raise_error(%r{is not supported}) end end end diff --git a/spec/unit/classes/lib/java_spec.rb b/spec/unit/classes/lib/java_spec.rb index 58ec2f8..4555293 100644 --- a/spec/unit/classes/lib/java_spec.rb +++ b/spec/unit/classes/lib/java_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe 'postgresql::lib::java', type: :class do describe 'on a debian based os' do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end it { is_expected.to contain_package('postgresql-jdbc').with( - name: 'libpg-java', + name: 'libpostgresql-jdbc-java', ensure: 'present', tag: 'postgresql', ) } end describe 'on a redhat based os' do let :facts do { osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '6.4', } end it { is_expected.to contain_package('postgresql-jdbc').with( name: 'postgresql-jdbc', ensure: 'present', tag: 'postgresql', ) } describe 'when parameters are supplied' do let :params do { package_ensure: 'latest', package_name: 'somepackage' } end it { is_expected.to contain_package('postgresql-jdbc').with( name: 'somepackage', ensure: 'latest', tag: 'postgresql', ) } end end end diff --git a/spec/unit/classes/lib/perl_spec.rb b/spec/unit/classes/lib/perl_spec.rb index d8c8a59..deeb5e9 100644 --- a/spec/unit/classes/lib/perl_spec.rb +++ b/spec/unit/classes/lib/perl_spec.rb @@ -1,37 +1,37 @@ require 'spec_helper' describe 'postgresql::lib::perl', type: :class do describe 'on a redhat based os' do let :facts do { osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '6.4', } end it { is_expected.to contain_package('perl-DBD-Pg').with( name: 'perl-DBD-Pg', ensure: 'present', ) } end describe 'on a debian based os' do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end it { is_expected.to contain_package('perl-DBD-Pg').with( name: 'libdbd-pg-perl', ensure: 'present', ) } end end diff --git a/spec/unit/classes/lib/python_spec.rb b/spec/unit/classes/lib/python_spec.rb index bbf93b4..7710447 100644 --- a/spec/unit/classes/lib/python_spec.rb +++ b/spec/unit/classes/lib/python_spec.rb @@ -1,37 +1,37 @@ require 'spec_helper' describe 'postgresql::lib::python', type: :class do describe 'on a redhat based os' do let :facts do { osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '6.4', } end it { is_expected.to contain_package('python-psycopg2').with( name: 'python-psycopg2', ensure: 'present', ) } end describe 'on a debian based os' do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end it { is_expected.to contain_package('python-psycopg2').with( name: 'python-psycopg2', ensure: 'present', ) } end end diff --git a/spec/unit/classes/params_spec.rb b/spec/unit/classes/params_spec.rb index 49dbb19..27b7195 100644 --- a/spec/unit/classes/params_spec.rb +++ b/spec/unit/classes/params_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe 'postgresql::params', type: :class do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end it { is_expected.to contain_class('postgresql::params') } end diff --git a/spec/unit/classes/repo_spec.rb b/spec/unit/classes/repo_spec.rb index f066093..1d8067d 100644 --- a/spec/unit/classes/repo_spec.rb +++ b/spec/unit/classes/repo_spec.rb @@ -1,27 +1,27 @@ require 'spec_helper' describe 'postgresql::repo', type: :class do let :facts do { os: { name: 'Debian', family: 'Debian', release: { - full: '6.0', - major: '6', + full: '8.0', + major: '8', }, }, osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', lsbdistid: 'Debian', - lsbdistcodename: 'squeeze', + lsbdistcodename: 'jessie', } end describe 'with no parameters' do it 'instantiates apt_postgresql_org class' do is_expected.to contain_class('postgresql::repo::apt_postgresql_org') end end end diff --git a/spec/unit/classes/server/contrib_spec.rb b/spec/unit/classes/server/contrib_spec.rb index d118ca0..529357d 100644 --- a/spec/unit/classes/server/contrib_spec.rb +++ b/spec/unit/classes/server/contrib_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' describe 'postgresql::server::contrib', type: :class do let :pre_condition do "class { 'postgresql::server': }" end let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end describe 'with parameters' do let(:params) do { package_name: 'mypackage', package_ensure: 'absent', } end it 'creates package with correct params' do is_expected.to contain_package('postgresql-contrib').with(ensure: 'absent', name: 'mypackage', tag: 'postgresql') end end describe 'with no parameters' do it 'creates package with postgresql tag' do is_expected.to contain_package('postgresql-contrib').with(tag: 'postgresql') end end describe 'on Gentoo' do let :facts do { osfamily: 'Gentoo', operatingsystem: 'Gentoo', } end it 'fails to compile' do expect { is_expected.to compile }.to raise_error(%r{is not supported}) end end end diff --git a/spec/unit/classes/server/plperl_spec.rb b/spec/unit/classes/server/plperl_spec.rb index 90d7d2d..c5614fe 100644 --- a/spec/unit/classes/server/plperl_spec.rb +++ b/spec/unit/classes/server/plperl_spec.rb @@ -1,43 +1,43 @@ require 'spec_helper' describe 'postgresql::server::plperl', type: :class do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('plperl'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :pre_condition do "class { 'postgresql::server': }" end describe 'with no parameters' do it { is_expected.to contain_class('postgresql::server::plperl') } it 'creates package' do is_expected.to contain_package('postgresql-plperl').with(ensure: 'present', tag: 'postgresql') end end describe 'with parameters' do let :params do { package_ensure: 'absent', package_name: 'mypackage', } end it { is_expected.to contain_class('postgresql::server::plperl') } it 'creates package with correct params' do is_expected.to contain_package('postgresql-plperl').with(ensure: 'absent', name: 'mypackage', tag: 'postgresql') end end end diff --git a/spec/unit/classes/server/postgis_spec.rb b/spec/unit/classes/server/postgis_spec.rb index b021bb3..666d6a9 100644 --- a/spec/unit/classes/server/postgis_spec.rb +++ b/spec/unit/classes/server/postgis_spec.rb @@ -1,40 +1,40 @@ require 'spec_helper' describe 'postgresql::server::postgis', type: :class do let :pre_condition do "class { 'postgresql::server': }" end let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('postgis'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end describe 'with parameters' do let(:params) do { package_name: 'mypackage', package_ensure: 'absent', } end it 'creates package with correct params' do is_expected.to contain_package('postgresql-postgis').with(ensure: 'absent', name: 'mypackage', tag: 'postgresql') end end describe 'with no parameters' do it 'creates package with postgresql tag' do is_expected.to contain_package('postgresql-postgis').with(tag: 'postgresql') end end end diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index 0667567..f202b4f 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -1,220 +1,220 @@ require 'spec_helper' describe 'postgresql::server', type: :class do let :facts do { os: { family: 'Debian', name: 'Debian', release: { - full: '6.0', - major: '6', + full: '8.0', + major: '8', }, }, osfamily: 'Debian', operatingsystem: 'Debian', lsbdistid: 'Debian', lsbdistcodename: 'jessie', operatingsystemrelease: '8.0', concat_basedir: tmpfilename('server'), kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end describe 'with no parameters' do it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it { is_expected.to contain_exec('postgresql_reload').with('command' => 'service postgresql reload') } it 'validates connection' do is_expected.to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'service_ensure => running' do let(:params) do { service_ensure: 'running', postgres_password: 'new-p@s$word-to-set', } end it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it { is_expected.to contain_class('postgresql::server::passwd') } it 'validates connection' do is_expected.to contain_postgresql_conn_validator('validate_service_is_running') end it 'sets postgres password' do is_expected.to contain_exec('set_postgres_postgrespw').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"', 'user' => 'postgres', 'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'], 'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null") end end describe 'service_ensure => stopped' do let(:params) { { service_ensure: 'stopped' } } it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it 'shouldnt validate connection' do is_expected.not_to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'service_restart_on_change => false' do let(:params) { { service_restart_on_change: false } } it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it { is_expected.not_to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]') } it 'validates connection' do is_expected.to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'service_restart_on_change => true' do let(:params) { { service_restart_on_change: true } } it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it { is_expected.to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]') } it 'validates connection' do is_expected.to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'service_reload => /bin/true' do let(:params) { { service_reload: '/bin/true' } } it { is_expected.to contain_class('postgresql::params') } it { is_expected.to contain_class('postgresql::server') } it { is_expected.to contain_exec('postgresql_reload').with('command' => '/bin/true') } it 'validates connection' do is_expected.to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'service_manage => true' do let(:params) { { service_manage: true } } it { is_expected.to contain_service('postgresqld') } end describe 'service_manage => false' do let(:params) { { service_manage: false } } it { is_expected.not_to contain_service('postgresqld') } it 'shouldnt validate connection' do is_expected.not_to contain_postgresql_conn_validator('validate_service_is_running') end end describe 'package_ensure => absent' do let(:params) do { package_ensure: 'absent', } end it 'removes the package' do is_expected.to contain_package('postgresql-server').with(ensure: 'purged') end it 'stills enable the service' do is_expected.to contain_service('postgresqld').with(ensure: 'running') end end describe 'needs_initdb => true' do let(:params) do { needs_initdb: true, } end it 'contains proper initdb exec' do is_expected.to contain_exec('postgresql_initdb') end end describe 'postgresql_version' do let(:pre_condition) do <<-EOS class { 'postgresql::globals': manage_package_repo => true, version => '99.5', before => Class['postgresql::server'], } EOS end it 'contains the correct package version' do is_expected.to contain_class('postgresql::repo').with_version('99.5') end end describe 'additional roles' do let(:params) do { roles: { username: { createdb: true }, }, } end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__role('username').with_createdb(true) } end describe 'additional config_entries' do let(:params) do { config_entries: { fsync: 'off', checkpoint_segments: '20', }, } end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__config_entry('fsync').with_value('off') } it { is_expected.to contain_postgresql__server__config_entry('checkpoint_segments').with_value('20') } end describe 'additional pg_hba_rules' do let(:params) do { pg_hba_rules: { from_remote_host: { type: 'host', database: 'mydb', user: 'myuser', auth_method: 'md5', address: '192.0.2.100', }, }, } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_postgresql__server__pg_hba_rule('from_remote_host') .with_type('host') .with_database('mydb') .with_user('myuser') .with_auth_method('md5') .with_address('192.0.2.100') end end end diff --git a/spec/unit/defines/server/database_grant_spec.rb b/spec/unit/defines/server/database_grant_spec.rb index d4c65b6..f3cd003 100644 --- a/spec/unit/defines/server/database_grant_spec.rb +++ b/spec/unit/defines/server/database_grant_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper' describe 'postgresql::server::database_grant', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { privilege: 'ALL', db: 'test', role: 'test', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__database_grant('test') } it { is_expected.to contain_postgresql__server__grant('database:test') } end diff --git a/spec/unit/defines/server/database_spec.rb b/spec/unit/defines/server/database_spec.rb index 9880bbc..67aaa2b 100644 --- a/spec/unit/defines/server/database_spec.rb +++ b/spec/unit/defines/server/database_spec.rb @@ -1,80 +1,80 @@ require 'spec_helper' describe 'postgresql::server::database', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__database('test') } it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"') } context "with comment set to 'test comment'" do let(:params) { { comment: 'test comment' } } it { is_expected.to contain_postgresql_psql("COMMENT ON DATABASE \"test\" IS 'test comment'").with_connect_settings({}) } end context 'with specific db connection settings - default port' do let :pre_condition do "class {'postgresql::server':}" end let(:params) do { connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1' } } end it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1').with_port(5432) } end context 'with specific db connection settings - including port' do let :pre_condition do "class {'postgresql::globals':} class {'postgresql::server':}" end let(:params) do { connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' } } end it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234').with_port(nil) } end context 'with global db connection settings - including port' do let :pre_condition do "class {'postgresql::globals': default_connect_settings => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.2', 'PGPORT' => '1234' } } class {'postgresql::server':}" end it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.2', 'PGPORT' => '1234').with_port(nil) } end context 'with different owner' do let(:params) { { owner: 'test_owner' } } it { is_expected.to contain_postgresql_psql('ALTER DATABASE "test" OWNER TO "test_owner"') } end end diff --git a/spec/unit/defines/server/db_spec.rb b/spec/unit/defines/server/db_spec.rb index 9dd9ad4..4ecb3b1 100644 --- a/spec/unit/defines/server/db_spec.rb +++ b/spec/unit/defines/server/db_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' describe 'postgresql::server::db', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end context 'without dbname param' do let :params do { user: 'test', password: 'test', owner: 'tester', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__db('test') } it { is_expected.to contain_postgresql__server__database('test').with_owner('tester') } it { is_expected.to contain_postgresql__server__role('test').that_comes_before('Postgresql::Server::Database[test]') } it { is_expected.to contain_postgresql__server__database_grant('GRANT test - ALL - test') } end context 'dbname' do let :params do { dbname: 'testtest', user: 'test', password: 'test', owner: 'tester', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__database('testtest') } end end diff --git a/spec/unit/defines/server/extension_spec.rb b/spec/unit/defines/server/extension_spec.rb index 84bd53d..b1f4358 100644 --- a/spec/unit/defines/server/extension_spec.rb +++ b/spec/unit/defines/server/extension_spec.rb @@ -1,153 +1,153 @@ 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 { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('postgis'), 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"]') } 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"]') } 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 { osfamily: 'Debian', operatingsystem: 'Debian', operatingsystemrelease: '6.0', kernel: 'Linux', concat_basedir: tmpfilename('postgis'), 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 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 diff --git a/spec/unit/defines/server/grant_role_spec.rb b/spec/unit/defines/server/grant_role_spec.rb index 6fbada8..c92173b 100644 --- a/spec/unit/defines/server/grant_role_spec.rb +++ b/spec/unit/defines/server/grant_role_spec.rb @@ -1,104 +1,104 @@ require 'spec_helper' describe 'postgresql::server::grant_role', type: :define do let :pre_condition do "class { 'postgresql::server': }" end let(:facts) do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('postgis'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' } end let(:title) { 'test' } let(:params) do { group: 'my_group', role: 'my_role', } end context 'with mandatory arguments only' do it { is_expected.to contain_postgresql_psql("grant_role:#{title}") .with(command: "GRANT \"#{params[:group]}\" TO \"#{params[:role]}\"", unless: "SELECT 1 WHERE EXISTS (SELECT 1 FROM pg_roles AS r_role JOIN pg_auth_members AS am ON r_role.oid = am.member JOIN pg_roles AS r_group ON r_group.oid = am.roleid WHERE r_group.rolname = '#{params[:group]}' AND r_role.rolname = '#{params[:role]}') = true") # rubocop:disable Metrics/LineLength .that_requires('Class[postgresql::server]') } end context 'with db arguments' do let(:params) do super().merge(psql_db: 'postgres', psql_user: 'postgres', port: '5432') end it { is_expected.to contain_postgresql_psql("grant_role:#{title}") .with(command: "GRANT \"#{params[:group]}\" TO \"#{params[:role]}\"", unless: "SELECT 1 WHERE EXISTS (SELECT 1 FROM pg_roles AS r_role JOIN pg_auth_members AS am ON r_role.oid = am.member JOIN pg_roles AS r_group ON r_group.oid = am.roleid WHERE r_group.rolname = '#{params[:group]}' AND r_role.rolname = '#{params[:role]}') = true", # rubocop:disable Metrics/LineLength db: params[:psql_db], psql_user: params[:psql_user], port: params[:port]).that_requires('Class[postgresql::server]') } end context 'with ensure => absent' do let(:params) do super().merge(ensure: 'absent') end it { is_expected.to contain_postgresql_psql("grant_role:#{title}") .with(command: "REVOKE \"#{params[:group]}\" FROM \"#{params[:role]}\"", unless: "SELECT 1 WHERE EXISTS (SELECT 1 FROM pg_roles AS r_role JOIN pg_auth_members AS am ON r_role.oid = am.member JOIN pg_roles AS r_group ON r_group.oid = am.roleid WHERE r_group.rolname = '#{params[:group]}' AND r_role.rolname = '#{params[:role]}') != true") # rubocop:disable Metrics/LineLength .that_requires('Class[postgresql::server]') } end context 'with user defined' do let(:pre_condition) do "class { 'postgresql::server': } postgresql::server::role { '#{params[:role]}': }" end it { is_expected.to contain_postgresql_psql("grant_role:#{title}").that_requires("Postgresql::Server::Role[#{params[:role]}]") } it { is_expected.not_to contain_postgresql_psql("grant_role:#{title}").that_requires("Postgresql::Server::Role[#{params[:group]}]") } end context 'with group defined' do let(:pre_condition) do "class { 'postgresql::server': } postgresql::server::role { '#{params[:group]}': }" end it { is_expected.to contain_postgresql_psql("grant_role:#{title}").that_requires("Postgresql::Server::Role[#{params[:group]}]") } it { is_expected.not_to contain_postgresql_psql("grant_role:#{title}").that_requires("Postgresql::Server::Role[#{params[:role]}]") } end context 'with connect_settings' do let(:params) do super().merge(connect_settings: { 'PGHOST' => 'postgres-db-server' }) end it { is_expected.to contain_postgresql_psql("grant_role:#{title}").with_connect_settings('PGHOST' => 'postgres-db-server') } it { is_expected.not_to contain_postgresql_psql("grant_role:#{title}").that_requires('Class[postgresql::server]') } end end diff --git a/spec/unit/defines/server/grant_spec.rb b/spec/unit/defines/server/grant_spec.rb index 850cd88..32bda6c 100644 --- a/spec/unit/defines/server/grant_spec.rb +++ b/spec/unit/defines/server/grant_spec.rb @@ -1,295 +1,295 @@ require 'spec_helper' describe 'postgresql::server::grant', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end context 'plain' do let :params do { db: 'test', role: 'test', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } end context 'sequence' do let :params do { db: 'test', role: 'test', privilege: 'usage', object_type: 'sequence', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it do is_expected.to contain_postgresql_psql('grant:test') .with_command(%r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m) .with_unless(%r{SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)}m) end end context 'SeQuEnCe case insensitive object_type match' do let :params do { db: 'test', role: 'test', privilege: 'usage', object_type: 'SeQuEnCe', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it do is_expected.to contain_postgresql_psql('grant:test') .with_command(%r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m) .with_unless(%r{SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)}m) end end context 'all sequences' do let :params do { db: 'test', role: 'test', privilege: 'usage', object_type: 'all sequences in schema', object_name: 'public', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it do is_expected.to contain_postgresql_psql('grant:test') .with_command(%r{GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"}m) .with_unless(%r{SELECT 1 WHERE NOT EXISTS \(\s*SELECT sequence_name\s* FROM information_schema\.sequences\s* WHERE sequence_schema='public'\s* EXCEPT DISTINCT\s* SELECT object_name as sequence_name\s* FROM .* WHERE .*grantee='test'\s* AND object_schema='public'\s* AND privilege_type='USAGE'\s*\)}m) # rubocop:disable Metrics/LineLength end end context 'with specific db connection settings - default port' do let :params do { db: 'test', role: 'test', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1' }, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1').with_port(5432) } end context 'with specific db connection settings - including port' do let :params do { db: 'test', role: 'test', 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__server__grant('test') } it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') } end context 'with specific db connection settings - port overriden by explicit parameter' do let :params do { db: 'test', role: 'test', 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__server__grant('test') } it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234').with_port('5678') } end context 'with specific schema name' do let :params do { db: 'test', role: 'test', privilege: 'all', object_name: ['myschema', 'mytable'], object_type: 'table', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it do is_expected.to contain_postgresql_psql('grant:test') .with_command(%r{GRANT ALL ON TABLE "myschema"."mytable" TO\s* "test"}m) .with_unless(%r{SELECT 1 WHERE has_table_privilege\('test',\s*'myschema.mytable', 'INSERT'\)}m) end end context 'with a role defined' do let :params do { db: 'test', role: 'test', privilege: 'all', object_name: ['myschema', 'mytable'], object_type: 'table', } end let :pre_condition do <<-EOS class {'postgresql::server':} postgresql::server::role { 'test': } EOS end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__grant('test') } it { is_expected.to contain_postgresql__server__role('test') } it do is_expected.to contain_postgresql_psql('grant:test') \ .that_requires(['Class[postgresql::server::service]', 'Postgresql::Server::Role[test]']) end end context 'invalid object_type' do let :params do { db: 'test', role: 'test', privilege: 'usage', object_type: 'invalid', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.and_raise_error(%r{parameter 'object_type' expects a match for Pattern}) } end context 'invalid object_name - wrong type' do let :params do { db: 'test', role: 'test', privilege: 'all', object_name: 1, object_type: 'table', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.and_raise_error(%r{parameter 'object_name' expects a value of type (Array|Undef, Array,) or String, got Integer}) } end context 'invalid object_name - insufficent array elements' do let :params do { db: 'test', role: 'test', privilege: 'all', object_name: ['oops'], object_type: 'table', } end let :pre_condition do "class {'postgresql::server':}" end if Puppet::Util::Package.versioncmp(Puppet.version, '5.2.0') >= 0 it { is_expected.to compile.and_raise_error(%r{parameter 'object_name' variant 1 expects size to be 2, got 1}) } else it { is_expected.to compile.and_raise_error(%r{parameter 'object_name' variant 0 expects size to be 2, got 1}) } end end context 'invalid object_name - too many array elements' do let :params do { db: 'test', role: 'test', privilege: 'all', object_name: ['myschema', 'mytable', 'oops'], object_type: 'table', } end let :pre_condition do "class {'postgresql::server':}" end if Puppet::Util::Package.versioncmp(Puppet.version, '5.2.0') >= 0 it { is_expected.to compile.and_raise_error(%r{parameter 'object_name' variant 1 expects size to be 2, got 3}) } else it { is_expected.to compile.and_raise_error(%r{parameter 'object_name' variant 0 expects size to be 2, got 3}) } end end end diff --git a/spec/unit/defines/server/pg_hba_rule_spec.rb b/spec/unit/defines/server/pg_hba_rule_spec.rb index 44b854c..4c3f977 100644 --- a/spec/unit/defines/server/pg_hba_rule_spec.rb +++ b/spec/unit/defines/server/pg_hba_rule_spec.rb @@ -1,148 +1,148 @@ require 'spec_helper' describe 'postgresql::server::pg_hba_rule', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('pg_hba'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :target do tmpfilename('pg_hba_rule') end context 'test template 1' do let :pre_condition do <<-MANIFEST class { 'postgresql::server': } MANIFEST end let :params do { type: 'host', database: 'all', user: 'all', address: '1.1.1.1/24', auth_method: 'md5', target: target, } end it do is_expected.to contain_concat__fragment('pg_hba_rule_test').with(content: %r{host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5}) end end context 'test template 2' do let :pre_condition do <<-MANIFEST class { 'postgresql::server': } MANIFEST end let :params do { type: 'local', database: 'all', user: 'all', auth_method: 'ident', target: target, } end it do is_expected.to contain_concat__fragment('pg_hba_rule_test').with(content: %r{local\s+all\s+all\s+ident}) end end context 'test template 3' do let :pre_condition do <<-MANIFEST class { 'postgresql::server': } MANIFEST end let :params do { type: 'host', database: 'all', user: 'all', address: '0.0.0.0/0', auth_method: 'ldap', auth_option: 'foo=bar', target: target, } end it do is_expected.to contain_concat__fragment('pg_hba_rule_test').with(content: %r{host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar}) end end context 'validation' do context 'validate supported auth_method' do let :pre_condition do <<-MANIFEST class { 'postgresql::globals': version => '9.2', } class { 'postgresql::server': } MANIFEST end let :params do { type: 'local', database: 'all', user: 'all', address: '0.0.0.0/0', auth_method: 'peer', target: target, } end it do is_expected.to contain_concat__fragment('pg_hba_rule_test').with( content: %r{local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer}, ) end end context 'allows scram-sha-256 on postgres 10' do let :pre_condition do <<-MANIFEST class { 'postgresql::globals': version => '10', } class { 'postgresql::server': } MANIFEST end let :params do { type: 'local', database: 'all', user: 'all', address: '0.0.0.0/0', auth_method: 'scram-sha-256', target: target, } end it do is_expected.to contain_concat__fragment('pg_hba_rule_test').with( content: %r{local\s+all\s+all\s+0\.0\.0\.0\/0\s+scram-sha-256}, ) end end end end diff --git a/spec/unit/defines/server/pg_ident_rule_spec.rb b/spec/unit/defines/server/pg_ident_rule_spec.rb index 68bdfb2..ece6322 100644 --- a/spec/unit/defines/server/pg_ident_rule_spec.rb +++ b/spec/unit/defines/server/pg_ident_rule_spec.rb @@ -1,66 +1,66 @@ require 'spec_helper' describe 'postgresql::server::pg_ident_rule', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('pg_ident'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :target do tmpfilename('pg_ident_rule') end context 'managing pg_ident' do let :pre_condition do <<-MANIFEST class { 'postgresql::globals': manage_pg_ident_conf => true, } class { 'postgresql::server': } MANIFEST end let :params do { map_name: 'thatsmymap', system_username: 'systemuser', database_username: 'dbuser', } end it do is_expected.to contain_concat__fragment('pg_ident_rule_test').with(content: %r{thatsmymap\s+systemuser\s+dbuser}) end end context 'not managing pg_ident' do let :pre_condition do <<-MANIFEST class { 'postgresql::globals': manage_pg_ident_conf => false, } class { 'postgresql::server': } MANIFEST end let :params do { map_name: 'thatsmymap', system_username: 'systemuser', database_username: 'dbuser', } end it 'fails because $manage_pg_ident_conf is false' do expect { catalogue }.to raise_error(Puppet::Error, %r{postgresql::server::manage_pg_ident_conf has been disabled}) end end end diff --git a/spec/unit/defines/server/reassign_owned_by_spec.rb b/spec/unit/defines/server/reassign_owned_by_spec.rb index c5a1794..761c517 100644 --- a/spec/unit/defines/server/reassign_owned_by_spec.rb +++ b/spec/unit/defines/server/reassign_owned_by_spec.rb @@ -1,44 +1,44 @@ require 'spec_helper' describe 'postgresql::server::reassign_owned_by', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('reassign_owned_by'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { db: 'test', old_role: 'test_old_role', new_role: 'test_new_role', } end let :pre_condition do <<-MANIFEST class {'postgresql::server':} postgresql::server::role{ ['test_old_role','test_new_role']: } MANIFEST end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql__server__reassign_owned_by('test') } it { is_expected.to contain_postgresql_psql('reassign_owned_by:test:REASSIGN OWNED BY "test_old_role" TO "test_new_role"') .with_command('REASSIGN OWNED BY "test_old_role" TO "test_new_role"') .with_onlyif(%r{SELECT tablename FROM pg_catalog.pg_tables WHERE\s*schemaname NOT IN \('pg_catalog', 'information_schema'\) AND\s*tableowner = 'test_old_role'.*}m) .that_requires('Class[Postgresql::Server::Service]') } end diff --git a/spec/unit/defines/server/recovery_spec.rb b/spec/unit/defines/server/recovery_spec.rb index 25bc132..d814175 100644 --- a/spec/unit/defines/server/recovery_spec.rb +++ b/spec/unit/defines/server/recovery_spec.rb @@ -1,115 +1,115 @@ require 'spec_helper' describe 'postgresql::server::recovery', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('recovery'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) do 'test' end let :target do tmpfilename('recovery') end context 'managing recovery' do let(:pre_condition) do <<-MANIFEST class { 'postgresql::globals': manage_recovery_conf => true, } class { 'postgresql::server': } MANIFEST end let(:params) do { restore_command: 'restore_command', recovery_target_timeline: 'recovery_target_timeline', } end it do is_expected.to contain_concat__fragment('recovery.conf') .with(content: %r{restore_command = 'restore_command'[\n]+recovery_target_timeline = 'recovery_target_timeline'}) end end context 'not managing recovery' do let(:pre_condition) do <<-MANIFEST class { 'postgresql::globals': manage_recovery_conf => false, } class { 'postgresql::server': } MANIFEST end let(:params) do { restore_command: '', } end it 'fails because $manage_recovery_conf is false' do expect { catalogue }.to raise_error(Puppet::Error, %r{postgresql::server::manage_recovery_conf has been disabled}) end end context 'not managing recovery, missing param' do let(:pre_condition) do <<-MANIFEST class { 'postgresql::globals': manage_recovery_conf => true, } class { 'postgresql::server': } MANIFEST end it 'fails because no param set' do expect { catalogue }.to raise_error(Puppet::Error, %r{postgresql::server::recovery use this resource but do not pass a parameter will avoid creating the recovery.conf, because it makes no sense.}) end end context 'managing recovery with all params' do let(:pre_condition) do <<-MANIFEST class { 'postgresql::globals': manage_recovery_conf => true, } class { 'postgresql::server': } MANIFEST end let(:params) do { restore_command: 'restore_command', archive_cleanup_command: 'archive_cleanup_command', recovery_end_command: 'recovery_end_command', recovery_target_name: 'recovery_target_name', recovery_target_time: 'recovery_target_time', recovery_target_xid: 'recovery_target_xid', recovery_target_inclusive: true, recovery_target: 'recovery_target', recovery_target_timeline: 'recovery_target_timeline', pause_at_recovery_target: true, standby_mode: 'on', primary_conninfo: 'primary_conninfo', primary_slot_name: 'primary_slot_name', trigger_file: 'trigger_file', recovery_min_apply_delay: 0, } end it do is_expected.to contain_concat__fragment('recovery.conf') .with(content: %r{restore_command = 'restore_command'[\n]+archive_cleanup_command = 'archive_cleanup_command'[\n]+recovery_end_command = 'recovery_end_command'[\n]+recovery_target_name = 'recovery_target_name'[\n]+recovery_target_time = 'recovery_target_time'[\n]+recovery_target_xid = 'recovery_target_xid'[\n]+recovery_target_inclusive = true[\n]+recovery_target = 'recovery_target'[\n]+recovery_target_timeline = 'recovery_target_timeline'[\n]+pause_at_recovery_target = true[\n]+standby_mode = on[\n]+primary_conninfo = 'primary_conninfo'[\n]+primary_slot_name = 'primary_slot_name'[\n]+trigger_file = 'trigger_file'[\n]+recovery_min_apply_delay = 0[\n]+}) # rubocop:disable Metrics/LineLength end end end diff --git a/spec/unit/defines/server/role_spec.rb b/spec/unit/defines/server/role_spec.rb index 3867eb4..ecf4abc 100644 --- a/spec/unit/defines/server/role_spec.rb +++ b/spec/unit/defines/server/role_spec.rb @@ -1,145 +1,145 @@ require 'spec_helper' describe 'postgresql::server::role', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('contrib'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { password_hash: 'new-pa$s', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__role('test') } it 'has create role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****') .with('command' => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1", 'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'", 'port' => '5432') end it 'has alter role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****') .with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'", 'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'", 'port' => '5432') end context 'with specific db connection settings - default port' do let :params do { password_hash: 'new-pa$s', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' }, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__role('test') } it 'has create role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****') .with_command("CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1") .with_environment('NEWPGPASSWD=new-pa$s') .with_unless("SELECT 1 FROM pg_roles WHERE rolname = 'test'") .with_port(5432) .with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass') .that_requires('Class[postgresql::server::service]') end it 'has alter role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****') .with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'", 'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'", 'port' => '5432', 'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' }) end end context 'with specific db connection settings - including port' do let :params do { password_hash: 'new-pa$s', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' }, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__role('test') } it 'has create role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****') .with('command' => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1", 'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'", 'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' }) end it 'has alter role for "test" user with password as ****' do is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****') .with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'", 'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'", 'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' }) end end context 'with update_password set to false' do let :params do { password_hash: 'new-pa$s', update_password: false, } end let :pre_condition do "class {'postgresql::server':}" end it 'does not have alter role for "test" user with password as **** if update_password is false' do is_expected.not_to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****') end end context 'with ensure set to absent' do let :params do { ensure: 'absent', } end let :pre_condition do "class {'postgresql::server':}" end it 'has drop role for "test" user if ensure absent' do is_expected.to contain_postgresql_psql('DROP ROLE "test"').that_requires('Class[postgresql::server::service]') end end end diff --git a/spec/unit/defines/server/schema_spec.rb b/spec/unit/defines/server/schema_spec.rb index a87f3dc..9cc0cac 100644 --- a/spec/unit/defines/server/schema_spec.rb +++ b/spec/unit/defines/server/schema_spec.rb @@ -1,43 +1,43 @@ require 'spec_helper' describe 'postgresql::server::schema', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('schema'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { owner: 'jane', db: 'janedb', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__schema('test') } context 'with different owner' do let :params do { owner: 'nate', db: 'natedb', } end it { is_expected.to contain_postgresql_psql('natedb: ALTER SCHEMA "test" OWNER TO "nate"') } end end diff --git a/spec/unit/defines/server/table_grant_spec.rb b/spec/unit/defines/server/table_grant_spec.rb index 4314eb2..804b4fa 100644 --- a/spec/unit/defines/server/table_grant_spec.rb +++ b/spec/unit/defines/server/table_grant_spec.rb @@ -1,35 +1,35 @@ require 'spec_helper' describe 'postgresql::server::table_grant', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('table_grant'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { privilege: 'ALL', db: 'test', role: 'test', table: 'foo', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__table_grant('test') } it { is_expected.to contain_postgresql__server__grant('table:test') } end diff --git a/spec/unit/defines/server/tablespace_spec.rb b/spec/unit/defines/server/tablespace_spec.rb index 7a3af76..e702e2a 100644 --- a/spec/unit/defines/server/tablespace_spec.rb +++ b/spec/unit/defines/server/tablespace_spec.rb @@ -1,43 +1,43 @@ require 'spec_helper' describe 'postgresql::server::tablespace', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', kernel: 'Linux', concat_basedir: tmpfilename('tablespace'), id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end let :params do { location: '/srv/data/foo', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql__server__tablespace('test') } it { is_expected.to contain_postgresql_psql('CREATE TABLESPACE "test"').that_requires('Class[postgresql::server::service]') } context 'with different owner' do let :params do { location: '/srv/data/foo', owner: 'test_owner', } end it { is_expected.to contain_postgresql_psql('ALTER TABLESPACE "test" OWNER TO "test_owner"') } end end diff --git a/spec/unit/defines/validate_db_connection_spec.rb b/spec/unit/defines/validate_db_connection_spec.rb index 243c591..2534f9a 100644 --- a/spec/unit/defines/validate_db_connection_spec.rb +++ b/spec/unit/defines/validate_db_connection_spec.rb @@ -1,66 +1,66 @@ require 'spec_helper' describe 'postgresql::validate_db_connection', type: :define do let :facts do { osfamily: 'Debian', operatingsystem: 'Debian', - operatingsystemrelease: '6.0', + operatingsystemrelease: '8.0', } end let :title do 'test' end describe 'should work with only default parameters' do it { is_expected.to contain_postgresql__validate_db_connection('test') } end describe 'should work with all parameters' do let :params do { database_host: 'test', database_name: 'test', database_password: 'test', database_username: 'test', database_port: 5432, run_as: 'postgresq', sleep: 4, tries: 30, } end it { is_expected.to contain_postgresql__validate_db_connection('test') } it 'has proper path for validate command' do is_expected.to contain_exec('validate postgres connection for test@test:5432/test').with(unless: %r{^/usr/local/bin/validate_postgresql_connection.sh\s+\d+}) end end describe 'should work while specifying validate_connection in postgresql::client' do let :params do { database_host: 'test', database_name: 'test', database_password: 'test', database_username: 'test', database_port: 5432, } end let :pre_condition do <<-MANIFEST class { 'postgresql::globals': module_workdir => '/var/tmp', } -> class { 'postgresql::client': validcon_script_path => '/opt/something/validate.sh' } MANIFEST end it 'has proper path for validate command and correct cwd' do is_expected.to contain_exec('validate postgres connection for test@test:5432/test').with(unless: %r{^/opt/something/validate.sh\s+\d+}, cwd: '/var/tmp') end end end