@@ -37,9 +37,7 @@ class { 'postgresql::server': }
3737
3838 puppet_apply ( pp ) do |r |
3939 r . exit_code . should_not == 1
40- end
41-
42- puppet_apply ( pp ) do |r |
40+ r . refresh
4341 r . exit_code . should == 0
4442 end
4543
@@ -78,9 +76,7 @@ class { 'postgresql::server': }
7876
7977 puppet_apply ( pp ) do |r |
8078 r . exit_code . should_not == 1
81- end
82-
83- puppet_apply ( pp ) do |r |
79+ r . refresh
8480 r . exit_code . should == 0
8581 end
8682
@@ -111,9 +107,7 @@ class { 'postgresql::server': }
111107
112108 puppet_apply ( pp ) do |r |
113109 r . exit_code . should_not == 1
114- end
115-
116- puppet_apply ( pp ) do |r |
110+ r . refresh
117111 r . exit_code . should == 0
118112 end
119113
@@ -146,9 +140,7 @@ class { 'postgresql::server': }
146140
147141 puppet_apply ( pp ) do |r |
148142 r . exit_code . should_not == 1
149- end
150-
151- puppet_apply ( pp ) do |r |
143+ r . refresh
152144 r . exit_code . should == 0
153145 end
154146
@@ -182,9 +174,7 @@ class { 'postgresql::server': }
182174 puppet_apply ( pp ) do |r |
183175 r . exit_code . should_not == 1
184176 r . stdout . should =~ /postgresql::psql is deprecated/
185- end
186-
187- puppet_apply ( pp ) do |r |
177+ r . refresh
188178 r . exit_code . should == 2
189179 r . stdout . should =~ /postgresql::psql is deprecated/
190180 end
@@ -207,9 +197,7 @@ class { 'postgresql::server': }
207197
208198 puppet_apply ( pp ) do |r |
209199 r . exit_code . should_not == 1
210- end
211-
212- puppet_apply ( pp ) do |r |
200+ r . refresh
213201 r . exit_code . should == 2
214202 end
215203 end
@@ -229,15 +217,13 @@ class { 'postgresql::server': }
229217
230218 puppet_apply ( pp ) do |r |
231219 r . exit_code . should_not == 1
232- end
233-
234- puppet_apply ( pp ) do |r |
235- r . exit_code . should be_zero
220+ r . refresh
221+ r . exit_code . should == 0
236222 end
237223 end
238224 end
239225
240- describe 'postgresql::user ' do
226+ describe 'postgresql::database_user ' do
241227 it 'should idempotently create a user who can log in' do
242228 pp = <<-EOS
243229 $user = "postgresql_test_user"
@@ -259,16 +245,14 @@ class { 'postgresql::server': }
259245
260246 puppet_apply ( pp ) do |r |
261247 r . exit_code . should_not == 1
262- end
263-
264- puppet_apply ( pp ) do |r |
265- r . exit_code . should be_zero
248+ r . refresh
249+ r . exit_code . should == 0
266250 end
267251
268252 # Check that the user can log in
269253 psql ( '--command="select datname from pg_database" postgres' , 'postgresql_test_user' ) do |r |
270254 r . stdout . should =~ /template1/
271- r . stderr . should be_empty
255+ r . stderr . should == ''
272256 r . exit_code . should == 0
273257 end
274258 end
@@ -294,16 +278,47 @@ class { 'postgresql::server': }
294278
295279 puppet_apply ( pp ) do |r |
296280 r . exit_code . should_not == 1
281+ r . refresh
282+ r . exit_code . should == 0
283+ end
284+
285+ # Check that the user can log in
286+ psql ( '--command="select datname from pg_database" postgres' , 'postgresql_test_user' ) do |r |
287+ r . stdout . should =~ /template1/
288+ r . stderr . should == ''
289+ r . exit_code . should == 0
297290 end
291+ end
292+
293+ it 'should idempotently create a user with a cleartext password' do
294+ pp = <<-EOS
295+ $user = "postgresql_test_user2"
296+ $password = "postgresql_test_password2"
297+
298+ include postgresql::server
299+
300+ # Since we are not testing pg_hba or any of that, make a local user for ident auth
301+ user { $user:
302+ ensure => present,
303+ }
304+
305+ postgresql::database_user { $user:
306+ password_hash => $password,
307+ require => [ Class['postgresql::server'],
308+ User[$user] ],
309+ }
310+ EOS
298311
299312 puppet_apply ( pp ) do |r |
300- r . exit_code . should be_zero
313+ r . exit_code . should_not == 1
314+ r . refresh
315+ r . exit_code . should == 0
301316 end
302317
303318 # Check that the user can log in
304- psql ( '--command="select datname from pg_database" postgres' , 'postgresql_test_user ' ) do |r |
319+ psql ( '--command="select datname from pg_database" postgres' , 'postgresql_test_user2 ' ) do |r |
305320 r . stdout . should =~ /template1/
306- r . stderr . should be_empty
321+ r . stderr . should == ''
307322 r . exit_code . should == 0
308323 end
309324 end
@@ -349,16 +364,14 @@ class { 'postgresql::server': }
349364
350365 puppet_apply ( pp ) do |r |
351366 r . exit_code . should_not == 1
352- end
353-
354- puppet_apply ( pp ) do |r |
355- r . exit_code . should be_zero
367+ r . refresh
368+ r . exit_code . should == 0
356369 end
357370
358371 # Check that the user can create a table in the database
359372 psql ( '--command="create table foo (foo int)" postgres' , 'psql_grant_tester' ) do |r |
360373 r . stdout . should =~ /CREATE TABLE/
361- r . stderr . should be_empty
374+ r . stderr . should == ''
362375 r . exit_code . should == 0
363376 end
364377 ensure
@@ -416,10 +429,8 @@ class { 'postgresql::server': }
416429
417430 puppet_apply ( pp ) do |r |
418431 r . exit_code . should_not == 1
419- end
420-
421- puppet_apply ( pp ) do |r |
422- r . exit_code . should be_zero
432+ r . refresh
433+ r . exit_code . should == 0
423434 end
424435
425436 ## Check that the user can create a table in the database
@@ -448,10 +459,8 @@ class { 'postgresql::server': }
448459
449460 puppet_apply ( pp ) do |r |
450461 r . exit_code . should_not == 1
451- end
452-
453- puppet_apply ( pp ) do |r |
454- r . exit_code . should be_zero
462+ r . refresh
463+ r . exit_code . should == 0
455464 end
456465
457466 pp = <<-EOS
@@ -464,7 +473,7 @@ class { 'postgresql::server': }
464473 EOS
465474
466475 puppet_apply ( pp ) do |r |
467- r . exit_code . should be_zero
476+ r . exit_code . should == 0
468477 end
469478 end
470479
@@ -537,22 +546,20 @@ class { 'postgresql::server': }
537546
538547 puppet_apply ( pp ) do |r |
539548 r . exit_code . should_not == 1
540- end
541-
542- puppet_apply ( pp ) do |r |
549+ r . refresh
543550 r . exit_code . should == 0
544551 end
545552
546553 # Check that databases use correct tablespaces
547554 psql ( '--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb1\'"\'"' ) do |r |
548555 r . stdout . should =~ /tablespace1/
549- r . stderr . should be_empty
556+ r . stderr . should == ''
550557 r . exit_code . should == 0
551558 end
552559
553560 psql ( '--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"' ) do |r |
554561 r . stdout . should =~ /tablespace2/
555- r . stderr . should be_empty
562+ r . stderr . should == ''
556563 r . exit_code . should == 0
557564 end
558565 end
@@ -633,16 +640,14 @@ class { 'pg_test': }
633640
634641 puppet_apply ( pp ) do |r |
635642 r . exit_code . should_not == 1
636- end
637-
638- puppet_apply ( pp ) do |r |
643+ r . refresh
639644 r . exit_code . should be_zero
640645 end
641646
642647 psql ( '--command="show max_connections" -t' ) do |r |
643648 r . stdout . should =~ /123/
644- r . stderr . should be_empty
645- r . exit_code . should be_zero
649+ r . stderr . should == ''
650+ r . exit_code . should == 0
646651 end
647652
648653 pp = <<-EOS
0 commit comments