File tree Expand file tree Collapse file tree 3 files changed +131
-0
lines changed Expand file tree Collapse file tree 3 files changed +131
-0
lines changed Original file line number Diff line number Diff line change 55
55
$manage_pg_ident_conf = $postgresql::params::manage_pg_ident_conf,
56
56
$manage_recovery_conf = $postgresql::params::manage_recovery_conf,
57
57
$module_workdir = $postgresql::params::module_workdir,
58
+
59
+ Hash[String, Hash] $roles = {},
60
+ Hash[String, Any] $config_entries = {},
61
+ Hash[String, Hash] $pg_hba_rules = {},
62
+
58
63
# Deprecated
59
64
$version = undef ,
60
65
) inherits postgresql::params {
85
90
-> Class[' postgresql::server::config' ]
86
91
-> Class[' postgresql::server::service' ]
87
92
-> Class[' postgresql::server::passwd' ]
93
+
94
+ $roles .each |$rolename , $role | {
95
+ postgresql::server::role { $rolename:
96
+ * => $role ,
97
+ }
98
+ }
99
+
100
+ $config_entries .each |$entry , $value | {
101
+ postgresql::server::config_entry { $entry:
102
+ value => $value ,
103
+ }
104
+ }
105
+
106
+ $pg_hba_rules .each |$rule_name , $rule | {
107
+ postgresql::server::pg_hba_rule { $rule_name:
108
+ * => $rule ,
109
+ }
110
+ }
88
111
}
Original file line number Diff line number Diff line change
1
+ require 'spec_helper_acceptance'
2
+
3
+ # These tests are designed to ensure that the module, when ran overrides,
4
+ # sets up everything correctly and allows us to connect to Postgres.
5
+ describe 'postgresql::server' , :unless => UNSUPPORTED_PLATFORMS . include? ( fact ( 'osfamily' ) ) do
6
+ it 'with defaults' do
7
+ pp = <<-EOS
8
+ class { 'postgresql::server':
9
+ roles => {
10
+ 'testusername' => {
11
+ password_hash => postgresql_password('testusername', 'supersecret'),
12
+ createdb => true,
13
+ },
14
+ },
15
+ config_entries => {
16
+ max_connections => 200,
17
+ },
18
+ pg_hba_rules => {
19
+ 'from_remote_host' => {
20
+ type => 'host',
21
+ database => 'mydb',
22
+ user => 'myuser',
23
+ auth_method => 'md5',
24
+ address => '192.0.2.100/32',
25
+ },
26
+ },
27
+ }
28
+
29
+ postgresql::server::database { 'testusername':
30
+ owner => 'testusername',
31
+ }
32
+ EOS
33
+
34
+ apply_manifest ( pp , :catch_failures => true )
35
+ apply_manifest ( pp , :catch_changes => true )
36
+ end
37
+
38
+ describe port ( 5432 ) do
39
+ it { is_expected . to be_listening }
40
+ end
41
+
42
+ it 'can connect with psql' do
43
+ psql ( '--command="\l" postgres' , 'postgres' ) do |r |
44
+ expect ( r . stdout ) . to match ( /List of databases/ )
45
+ end
46
+ end
47
+
48
+ it 'can connect with psql as testusername' do
49
+ shell ( 'PGPASSWORD=supersecret psql -U testusername -h localhost --command="\l"' ) do |r |
50
+ expect ( r . stdout ) . to match ( /List of databases/ )
51
+ end
52
+ end
53
+
54
+ end
Original file line number Diff line number Diff line change @@ -165,4 +165,58 @@ class { 'postgresql::globals':
165
165
is_expected . to contain_class ( 'postgresql::repo' ) . with_version ( '99.5' )
166
166
end
167
167
end
168
+
169
+ describe 'additional roles' do
170
+ let ( :params ) do
171
+ {
172
+ :roles => {
173
+ :username => { :createdb => true }
174
+ }
175
+ }
176
+ end
177
+
178
+ it { is_expected . to compile . with_all_deps }
179
+ it { is_expected . to contain_postgresql__server__role ( 'username' ) . with_createdb ( true ) }
180
+ end
181
+
182
+ describe 'additional config_entries' do
183
+ let ( :params ) do
184
+ {
185
+ :config_entries => {
186
+ :fsync => 'off' ,
187
+ :checkpoint_segments => '20'
188
+ }
189
+ }
190
+ end
191
+
192
+ it { is_expected . to compile . with_all_deps }
193
+ it { is_expected . to contain_postgresql__server__config_entry ( 'fsync' ) . with_value ( 'off' ) }
194
+ it { is_expected . to contain_postgresql__server__config_entry ( 'checkpoint_segments' ) . with_value ( '20' ) }
195
+ end
196
+
197
+ describe 'additional pg_hba_rules' do
198
+ let ( :params ) do
199
+ {
200
+ :pg_hba_rules => {
201
+ :from_remote_host => {
202
+ :type => 'host' ,
203
+ :database => 'mydb' ,
204
+ :user => 'myuser' ,
205
+ :auth_method => 'md5' ,
206
+ :address => '192.0.2.100'
207
+ }
208
+ }
209
+ }
210
+ end
211
+
212
+ it { is_expected . to compile . with_all_deps }
213
+ it do
214
+ is_expected . to contain_postgresql__server__pg_hba_rule ( 'from_remote_host' ) . \
215
+ with_type ( 'host' ) . \
216
+ with_database ( 'mydb' ) . \
217
+ with_user ( 'myuser' ) . \
218
+ with_auth_method ( 'md5' ) . \
219
+ with_address ( '192.0.2.100' )
220
+ end
221
+ end
168
222
end
You can’t perform that action at this time.
0 commit comments