-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for postgresql::server::db when using a Deferred password
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
describe 'postgresql::server::db' do | ||
before(:all) do | ||
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}) | ||
end | ||
|
||
it 'creates a database with a deferred password' do | ||
tmpdir = run_shell('mktemp').stdout | ||
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 => Deferred('unwrap', ['test1']) | ||
tablespace => 'postgresql-test-db', | ||
} | ||
MANIFEST | ||
|
||
idempotent_apply(pp) | ||
|
||
# Verify that the postgres password works | ||
run_shell("echo 'localhost:*:*:postgres:'space password'' > /root/.pgpass") | ||
run_shell('chmod 600 /root/.pgpass') | ||
run_shell("psql -U postgres -h localhost --command='\\l'") | ||
|
||
result = psql('--command="select datname from pg_database" "postgresql-test-db"') | ||
expect(result.stdout).to match(%r{postgresql-test-db}) | ||
expect(result.stderr).to eq('') | ||
|
||
result = psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"') | ||
expect(result.stdout).to match(%r{\(1 row\)}) | ||
|
||
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 | ||
expect(result.stdout).to match(%r{\(1 row\)}) | ||
ensure | ||
psql('--command=\'drop database "postgresql-test-db"\'') | ||
end | ||
end |