autofs: add debian-debug at ubc
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / acceptance / db_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   it 'creates a database' do
5     begin
6       tmpdir = default.tmpdir('postgresql')
7       pp = <<-EOS
8         class { 'postgresql::server':
9           postgres_password => 'space password',
10         }
11         postgresql::server::tablespace { 'postgresql-test-db':
12           location => '#{tmpdir}',
13         } ->
14         postgresql::server::db { 'postgresql-test-db':
15           comment    => 'testcomment',
16           user       => 'test-user',
17           password   => 'test1',
18           tablespace => 'postgresql-test-db',
19         }
20       EOS
21
22       apply_manifest(pp, :catch_failures => true)
23       apply_manifest(pp, :catch_changes => true)
24
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'")
29
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('')
33       end
34
35       psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"') do |r|
36         expect(r.stdout).to match(/\(1 row\)/)
37       end
38
39       result = shell('psql --version')
40       version = result.stdout.match(%r{\s(\d\.\d)})[1]
41       if version > "8.1"
42         comment_information_function = "shobj_description"
43       else
44         comment_information_function = "obj_description"
45       end
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\)/)
48       end
49     ensure
50       psql('--command=\'drop database "postgresql-test-db" postgres\'')
51       psql('--command="DROP USER test"')
52     end
53   end
54 end