File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 425425 }
426426 # Never put double quotes into has_*_privilege function
427427 $_granted_object = join($_object_name, ' .' )
428+ # pg_* views does not contain schema name as part of the object name
429+ $_togrant_object_only = $_object_name[1]
428430 }
429431 default: {
430432 $_granted_object = $_object_name
445447 }
446448
447449 $_onlyif = $onlyif_function ? {
448- ' table_exists' => " SELECT true FROM pg_tables WHERE tablename = '${_togrant_object }'" ,
449- ' language_exists' => " SELECT true from pg_language WHERE lanname = '${_togrant_object }'" ,
450+ ' table_exists' => " SELECT true FROM pg_tables WHERE tablename = '${_togrant_object_only }'" ,
451+ ' language_exists' => " SELECT true from pg_language WHERE lanname = '${_togrant_object_only} }'" ,
450452 ' role_exists' => " SELECT 1 FROM pg_roles WHERE rolname = '${role} ' or '${role} ' = 'PUBLIC'" ,
451- ' function_exists' => " SELECT true FROM pg_proc WHERE (oid::regprocedure)::text = '${_togrant_object }${arguments} '" ,
453+ ' function_exists' => " SELECT true FROM pg_proc WHERE (oid::regprocedure)::text = '${_togrant_object_only} }${arguments} '" ,
452454 default => undef ,
453455 }
454456
Original file line number Diff line number Diff line change @@ -384,4 +384,30 @@ class {'postgresql::server':}
384384 it { is_expected . to compile . and_raise_error ( %r{parameter 'object_name' variant 0 expects size to be 2, got 3} ) }
385385 end
386386 end
387+
388+ context 'with specific schema name only if object exists' do
389+ let :params do
390+ {
391+ db : 'test' ,
392+ role : 'test' ,
393+ privilege : 'all' ,
394+ object_name : [ 'myschema' , 'mytable' ] ,
395+ object_type : 'table' ,
396+ onlyif_exists : true ,
397+ }
398+ end
399+
400+ let :pre_condition do
401+ "class {'postgresql::server':}"
402+ end
403+
404+ it { is_expected . to compile . with_all_deps }
405+ it { is_expected . to contain_postgresql__server__grant ( 'test' ) }
406+ it do
407+ is_expected . to contain_postgresql_psql ( 'grant:test' )
408+ . with_command ( %r{GRANT ALL ON TABLE "myschema"."mytable" TO\s * "test"}m )
409+ . with_unless ( %r{SELECT 1 WHERE has_table_privilege\( 'test',\s *'myschema.mytable', 'INSERT'\) }m )
410+ . with_onlyif ( %r{SELECT true FROM pg_tables WHERE tablename = 'mytable'}m )
411+ end
412+ end
387413end
You can’t perform that action at this time.
0 commit comments