Skip to content

Commit 5609bd0

Browse files
committed
Add a test for postgresql::server::db when using a Deferred password
1 parent 167412d commit 5609bd0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Diff for: spec/acceptance/db_deferred_spec.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'postgresql::server::db' do
6+
before(:all) do
7+
LitmusHelper.instance.run_shell("cd /tmp; su 'postgres' -c 'pg_ctl stop -D /var/lib/pgsql/data/ -m fast'", acceptable_exit_codes: [0, 1]) unless os[:family].match?(%r{debian|ubuntu})
8+
end
9+
10+
it 'creates a database with a deferred password' do
11+
tmpdir = run_shell('mktemp').stdout
12+
pp = <<-MANIFEST
13+
class { 'postgresql::server':
14+
postgres_password => 'space password',
15+
}
16+
postgresql::server::tablespace { 'postgresql-test-db':
17+
location => '#{tmpdir}',
18+
} ->
19+
postgresql::server::db { 'postgresql-test-db':
20+
comment => 'testcomment',
21+
user => 'test-user',
22+
password => Deferred('unwrap', ['test1'])
23+
tablespace => 'postgresql-test-db',
24+
}
25+
MANIFEST
26+
27+
idempotent_apply(pp)
28+
29+
# Verify that the postgres password works
30+
run_shell("echo 'localhost:*:*:postgres:'space password'' > /root/.pgpass")
31+
run_shell('chmod 600 /root/.pgpass')
32+
run_shell("psql -U postgres -h localhost --command='\\l'")
33+
34+
result = psql('--command="select datname from pg_database" "postgresql-test-db"')
35+
expect(result.stdout).to match(%r{postgresql-test-db})
36+
expect(result.stderr).to eq('')
37+
38+
result = psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"')
39+
expect(result.stdout).to match(%r{\(1 row\)})
40+
41+
result = psql("--dbname postgresql-test-db --command=\"SELECT pg_catalog.shobj_description(d.oid, 'pg_database') FROM pg_catalog.pg_database d WHERE datname = 'postgresql-test-db' AND pg_catalog.shobj_description(d.oid, 'pg_database') = 'testcomment'\"") # rubocop:disable Layout/LineLength
42+
expect(result.stdout).to match(%r{\(1 row\)})
43+
ensure
44+
psql('--command=\'drop database "postgresql-test-db"\'')
45+
end
46+
end

0 commit comments

Comments
 (0)