Skip to content

Commit 939e909

Browse files
committed
Simplify Deferred postgresql::server::db Deferred test
1 parent 0512cd6 commit 939e909

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

Diff for: spec/acceptance/db_deferred_spec.rb

+24-37
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,32 @@
22

33
require 'spec_helper_acceptance'
44

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',
5+
describe 'postgresql::server::db:' do
6+
let(:user) { 'user_test' }
7+
let(:password) { 'deferred_password_test' }
8+
let(:database) { 'test_database' }
9+
10+
let(:pp_one) do
11+
<<-MANIFEST.unindent
12+
$user = #{user}
13+
$password = #{password}
14+
$database = #{database}
15+
16+
include postgresql::server
17+
postgresql::server::db { $database:
18+
user => $user,
19+
password => Deferred('unwrap', [$password]),
2420
}
2521
MANIFEST
22+
end
2623

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"\'')
24+
it 'creates a database with with the password in the deferred function' do
25+
if run_shell('puppet --version').stdout[0].to_i < 7
26+
skip # Deferred function fixes only in puppet 7, see https://tickets.puppetlabs.com/browse/PUP-11518
27+
end
28+
apply_manifest(pp_one)
29+
psql_cmd = "PGPASSWORD=#{password} PGUSER=#{user} PGDATABASE=#{database} psql -h 127.0.0.1 -d postgres -c '\\q'"
30+
run_shell("cd /tmp; su #{shellescape('postgres')} -c #{shellescape(psql_cmd)}",
31+
acceptable_exit_codes: [0])
4532
end
4633
end

0 commit comments

Comments
 (0)