forked from puppetlabs/puppetlabs-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostgresql_conn_validator_spec.rb
More file actions
76 lines (65 loc) · 2 KB
/
Copy pathpostgresql_conn_validator_spec.rb
File metadata and controls
76 lines (65 loc) · 2 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'spec_helper_acceptance'
describe 'postgresql_conn_validator', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
let(:install_pp) { <<-EOS
class { 'postgresql::server':
postgres_password => 'space password',
}->
postgresql::server::role { 'testuser':
password_hash => postgresql_password('testuser','test1'),
}->
postgresql::server::database { 'testdb':
owner => 'testuser',
require => Postgresql::Server::Role['testuser']
}->
postgresql::server::database_grant { 'allow connect for testuser':
privilege => 'ALL',
db => 'testdb',
role => 'testuser',
}
EOS
}
context 'local connection' do
it 'validates successfully with defaults' do
pp = <<-EOS
#{install_pp}->
postgresql_conn_validator { 'validate this':
db_name => 'testdb',
db_username => 'testuser',
db_password => 'test1',
host => 'localhost',
psql_path => '/usr/bin/psql',
}
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
it 'works with connect settings hash' do
pp = <<-EOS
#{install_pp}->
postgresql_conn_validator { 'validate this':
connect_settings => {
'PGDATABASE' => 'testdb',
'PGPORT' => '5432',
'PGUSER' => 'testuser',
'PGPASSWORD' => 'test1',
'PGHOST' => 'localhost'
},
psql_path => '/usr/bin/psql'
}
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
it 'fails gracefully' do
pp = <<-EOS
#{install_pp}->
postgresql_conn_validator { 'validate this':
psql_path => '/usr/bin/psql',
tries => 3
}
EOS
result = apply_manifest(pp)
expect(result.stderr).to match /Unable to connect to PostgreSQL server/
end
end
end