3 describe 'postgresql::server::grant', :type => :define do
7 :operatingsystem => 'Debian',
8 :operatingsystemrelease => '6.0',
10 :concat_basedir => tmpfilename('contrib'),
12 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
29 "class {'postgresql::server':}"
32 it { is_expected.to contain_postgresql__server__grant('test') }
40 :privilege => 'usage',
41 :object_type => 'sequence',
46 "class {'postgresql::server':}"
49 it { is_expected.to contain_postgresql__server__grant('test') }
50 it { is_expected.to contain_postgresql_psql('grant:test').with(
52 'command' => /GRANT USAGE ON SEQUENCE "test" TO\s* "test"/m,
53 'unless' => /SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)/m,
58 context 'all sequences' do
63 :privilege => 'usage',
64 :object_type => 'all sequences in schema',
65 :object_name => 'public',
70 "class {'postgresql::server':}"
73 it { is_expected.to contain_postgresql__server__grant('test') }
74 it { is_expected.to contain_postgresql_psql('grant:test').with(
76 'command' => /GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"/m,
77 'unless' => /SELECT 1 FROM \(\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*\) P\s* HAVING count\(P\.sequence_name\) = 0/m,
82 context "with specific db connection settings - default port" do
87 :connect_settings => { 'PGHOST' => 'postgres-db-server',
88 'DBVERSION' => '9.1', },
93 "class {'postgresql::server':}"
96 it { is_expected.to contain_postgresql__server__grant('test') }
97 it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1' } ).with_port( 5432 ) }
100 context "with specific db connection settings - including port" do
105 :connect_settings => { 'PGHOST' => 'postgres-db-server',
106 'DBVERSION' => '9.1',
107 'PGPORT' => '1234', },
111 let :pre_condition do
112 "class {'postgresql::server':}"
115 it { is_expected.to contain_postgresql__server__grant('test') }
116 it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1','PGPORT' => '1234' } ) }
119 context "with specific db connection settings - port overriden by explicit parameter" do
124 :connect_settings => { 'PGHOST' => 'postgres-db-server',
125 'DBVERSION' => '9.1',
126 'PGPORT' => '1234', },
131 let :pre_condition do
132 "class {'postgresql::server':}"
135 it { is_expected.to contain_postgresql__server__grant('test') }
136 it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1','PGPORT' => '1234' } ).with_port( '5678' ) }
139 context 'invalid objectype' do
144 :privilege => 'usage',
145 :object_type => 'invalid',
149 let :pre_condition do
150 "class {'postgresql::server':}"
153 it { is_expected.to compile.and_raise_error(/"INVALID" does not match/) }