wuiet.d.o no longer needs access to projectb on bmdb1
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / acceptance / postgresql_conn_validator_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'postgresql_conn_validator', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4
5   let(:install_pp) { <<-EOS
6     class { 'postgresql::server':
7       postgres_password => 'space password',
8     }->
9     postgresql::server::role { 'testuser':
10       password_hash => postgresql_password('testuser','test1'),
11     }->
12     postgresql::server::database { 'testdb':
13       owner   => 'testuser',
14       require => Postgresql::Server::Role['testuser']
15     }->
16     postgresql::server::database_grant { 'allow connect for testuser':
17       privilege => 'ALL',
18       db        => 'testdb',
19       role      => 'testuser',
20     }
21
22   EOS
23
24   }
25
26   context 'local connection' do
27     it 'validates successfully with defaults' do
28       pp = <<-EOS
29         #{install_pp}->
30         postgresql_conn_validator { 'validate this':
31           db_name     => 'testdb',
32           db_username => 'testuser',
33           db_password => 'test1',
34           host        => 'localhost',
35           psql_path   => '/usr/bin/psql',
36         }
37     EOS
38
39       apply_manifest(pp, :catch_failures => true)
40       apply_manifest(pp, :catch_changes => true)
41     end
42
43     it 'works with connect settings hash' do
44       pp = <<-EOS
45         #{install_pp}->
46         postgresql_conn_validator { 'validate this':
47           connect_settings => {
48             'PGDATABASE' => 'testdb',
49             'PGPORT'     => '5432',
50             'PGUSER'     => 'testuser',
51             'PGPASSWORD' => 'test1',
52             'PGHOST'     => 'localhost'
53           },
54           psql_path => '/usr/bin/psql'
55         }
56      EOS
57
58       apply_manifest(pp, :catch_failures => true)
59       apply_manifest(pp, :catch_changes => true)
60
61     end
62
63     it 'fails gracefully' do
64       pp = <<-EOS
65         #{install_pp}->
66         postgresql_conn_validator { 'validate this':
67           psql_path => '/usr/bin/psql',
68           tries     => 3
69         }
70      EOS
71
72       result = apply_manifest(pp)
73       expect(result.stderr).to match /Unable to connect to PostgreSQL server/
74     end
75   end
76 end