forked from puppetlabs/puppetlabs-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_spec.rb
55 lines (49 loc) · 2.17 KB
/
db_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper_acceptance'
describe 'postgresql::server::db', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
# rubocop:disable Metrics/LineLength
it 'creates a database' do
begin
tmpdir = default.tmpdir('postgresql')
pp = <<-MANIFEST
class { 'postgresql::server':
postgres_password => 'space password',
}
postgresql::server::tablespace { 'postgresql-test-db':
location => '#{tmpdir}',
} ->
postgresql::server::db { 'postgresql-test-db':
comment => 'testcomment',
user => 'test-user',
password => 'test1',
tablespace => 'postgresql-test-db',
}
MANIFEST
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# 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'")
psql('--command="select datname from pg_database" "postgresql-test-db"') do |r|
expect(r.stdout).to match(%r{postgresql-test-db})
expect(r.stderr).to eq('')
end
psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"') do |r|
expect(r.stdout).to match(%r{\(1 row\)})
end
result = shell('psql --version')
version = result.stdout.match(%r{\s(\d{1,2}\.\d)})[1]
comment_information_function = if version.to_f > 8.1
'shobj_description'
else
'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|
expect(r.stdout).to match(%r{\(1 row\)})
end
ensure
psql('--command=\'drop database "postgresql-test-db" postgres\'')
psql('--command="DROP USER test"')
end
end
end