2014-07-09 22:37:29 +02:00
require 'spec_helper_acceptance'
describe 'postgresql::server::db' , :unless = > UNSUPPORTED_PLATFORMS . include? ( fact ( 'osfamily' ) ) do
it 'creates a database' do
begin
tmpdir = default . tmpdir ( 'postgresql' )
pp = <<-EOS
2015-04-10 23:28:18 +02:00
class { 'postgresql::server' :
postgres_password = > 'space password' ,
}
2014-07-09 22:37:29 +02:00
postgresql :: server :: tablespace { 'postgresql_test_db' :
location = > '#{tmpdir}' ,
} - >
postgresql :: server :: db { 'postgresql_test_db' :
2015-01-09 04:08:23 +01:00
comment = > 'testcomment' ,
2014-07-09 22:37:29 +02:00
user = > 'test' ,
password = > 'test1' ,
tablespace = > 'postgresql_test_db' ,
}
EOS
apply_manifest ( pp , :catch_failures = > true )
apply_manifest ( pp , :catch_changes = > true )
2015-04-10 23:28:18 +02:00
# Verify that the postgres password works
shell ( " echo 'localhost:*:*:postgres:space password' > /root/.pgpass " )
shell ( " chmod 600 /root/.pgpass " )
shell ( " psql -U postgres -h localhost --command=' \\ l' " )
2014-07-09 22:37:29 +02:00
psql ( '--command="select datname from pg_database" postgresql_test_db' ) do | r |
expect ( r . stdout ) . to match ( / postgresql_test_db / )
expect ( r . stderr ) . to eq ( '' )
end
psql ( '--command="SELECT 1 FROM pg_roles WHERE rolname=\'test\'"' ) do | r |
expect ( r . stdout ) . to match ( / \ (1 row \ ) / )
end
2015-01-09 04:08:23 +01:00
2015-02-04 22:41:11 +01:00
result = shell ( 'psql --version' )
2015-02-06 17:40:22 +01:00
version = result . stdout . match ( %r{ \ s( \ d \ . \ d) } ) [ 1 ]
2015-02-04 22:41:11 +01:00
if version > " 8.1 "
comment_information_function = " shobj_description "
else
comment_information_function = " obj_description "
end
psql ( " --dbname postgresql_test_db --command= \" SELECT pg_catalog. #{ comment_information_function } (d.oid, 'pg_database') FROM pg_catalog.pg_database d WHERE datname = 'postgresql_test_db' AND pg_catalog. #{ comment_information_function } (d.oid, 'pg_database') = 'testcomment' \" " ) do | r |
2015-01-09 04:08:23 +01:00
expect ( r . stdout ) . to match ( / \ (1 row \ ) / )
end
2014-07-09 22:37:29 +02:00
ensure
psql ( '--command="drop database postgresql_test_db" postgres' )
psql ( '--command="DROP USER test"' )
end
end
end