1 require 'spec_helper_acceptance'
3 describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4 it 'creates a database' do
6 tmpdir = default.tmpdir('postgresql')
8 class { 'postgresql::server':
9 postgres_password => 'space password',
11 postgresql::server::tablespace { 'postgresql-test-db':
12 location => '#{tmpdir}',
14 postgresql::server::db { 'postgresql-test-db':
15 comment => 'testcomment',
18 tablespace => 'postgresql-test-db',
22 apply_manifest(pp, :catch_failures => true)
23 apply_manifest(pp, :catch_changes => true)
25 # Verify that the postgres password works
26 shell("echo 'localhost:*:*:postgres:\'space password\'' > /root/.pgpass")
27 shell("chmod 600 /root/.pgpass")
28 shell("psql -U postgres -h localhost --command='\\l'")
30 psql('--command="select datname from pg_database" "postgresql-test-db"') do |r|
31 expect(r.stdout).to match(/postgresql-test-db/)
32 expect(r.stderr).to eq('')
35 psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"') do |r|
36 expect(r.stdout).to match(/\(1 row\)/)
39 result = shell('psql --version')
40 version = result.stdout.match(%r{\s(\d\.\d)})[1]
42 comment_information_function = "shobj_description"
44 comment_information_function = "obj_description"
46 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|
47 expect(r.stdout).to match(/\(1 row\)/)
50 psql('--command=\'drop database "postgresql-test-db" postgres\'')
51 psql('--command="DROP USER test"')