Skip to content

Commit ba8c9f4

Browse files
committed
Fixup for tests
1 parent 3d8a411 commit ba8c9f4

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

spec/acceptance/server/default_privileges_spec.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,25 @@ class { 'postgresql::server': }
6969
end
7070

7171
it 'grants default privileges to an user' do
72-
idempotent_apply(pp_one)
72+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
73+
idempotent_apply(pp_one)
7374

74-
psql("--command=\"SET client_min_messages = 'error';#{check_command}\" --db=#{db}") do |r|
75-
expect(r.stdout).to match(%r{\(1 row\)})
76-
expect(r.stderr).to eq('')
75+
psql("--command=\"SET client_min_messages = 'error';#{check_command}\" --db=#{db}") do |r|
76+
expect(r.stdout).to match(%r{\(1 row\)})
77+
expect(r.stderr).to eq('')
78+
end
7779
end
7880
end
7981

8082
it 'revokes default privileges for an user' do
81-
apply_manifest(pp_one, catch_failures: true)
82-
apply_manifest(pp_two, expect_changes: true)
83+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
84+
apply_manifest(pp_one, catch_failures: true)
85+
apply_manifest(pp_two, expect_changes: true)
8386

84-
psql("--command=\"SET client_min_messages = 'error';#{check_command}\" --db=#{db}") do |r|
85-
expect(r.stdout).to match(%r{\(0 rows\)})
86-
expect(r.stderr).to eq('')
87+
psql("--command=\"SET client_min_messages = 'error';#{check_command}\" --db=#{db}") do |r|
88+
expect(r.stdout).to match(%r{\(0 rows\)})
89+
expect(r.stderr).to eq('')
90+
end
8791
end
8892
end
8993
end

spec/unit/defines/server/default_privileges_spec.rb

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4+
require 'spec_helper_acceptance'
45

56
describe 'postgresql::server::default_privileges', type: :define do
67
let :facts do
@@ -64,11 +65,13 @@
6465
"class {'postgresql::server':}"
6566
end
6667

67-
it { is_expected.to compile.with_all_deps }
68-
it { is_expected.to contain_postgresql__server__default_privileges('test') }
69-
it do
70-
is_expected.to contain_postgresql_psql('default_privileges:test')
71-
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"')
68+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
69+
it { is_expected.to compile.with_all_deps }
70+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
71+
it do
72+
is_expected.to contain_postgresql_psql('default_privileges:test')
73+
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"')
74+
end
7275
end
7376
end
7477

@@ -87,7 +90,9 @@
8790
"class {'postgresql::server':}"
8891
end
8992

90-
it { is_expected.to compile.and_raise_error(%r{parameter 'object_type' expects a match for Pattern}) }
93+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
94+
it { is_expected.to compile.and_raise_error(%r{parameter 'object_type' expects a match for Pattern}) }
95+
end
9196
end
9297
end
9398

@@ -106,14 +111,16 @@
106111
"class {'postgresql::server':}"
107112
end
108113

109-
it { is_expected.to compile.with_all_deps }
110-
it { is_expected.to contain_postgresql__server__default_privileges('test') }
111-
it do
112-
# rubocop:disable Layout/LineLength
113-
is_expected.to contain_postgresql_psql('default_privileges:test')
114-
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"')
115-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
116-
# rubocop:enable Layout/LineLength
114+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
115+
it { is_expected.to compile.with_all_deps }
116+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
117+
it do
118+
# rubocop:disable Layout/LineLength
119+
is_expected.to contain_postgresql_psql('default_privileges:test')
120+
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"')
121+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
122+
# rubocop:enable Layout/LineLength
123+
end
117124
end
118125
end
119126

@@ -131,7 +138,9 @@
131138
"class {'postgresql::server':}"
132139
end
133140

134-
it { is_expected.to compile.and_raise_error(%r{Illegal value for \$privilege parameter}) }
141+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
142+
it { is_expected.to compile.and_raise_error(%r{Illegal value for \$privilege parameter}) }
143+
end
135144
end
136145
end
137146

@@ -216,14 +225,16 @@
216225
"class {'postgresql::server':}"
217226
end
218227

219-
it { is_expected.to compile.with_all_deps }
220-
it { is_expected.to contain_postgresql__server__default_privileges('test') }
221-
it do
222-
# rubocop:disable Layout/LineLength
223-
is_expected.to contain_postgresql_psql('default_privileges:test')
224-
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema GRANT ALL ON TABLES TO "test"')
225-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')")
226-
# rubocop:enable Layout/LineLength
228+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
229+
it { is_expected.to compile.with_all_deps }
230+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
231+
it do
232+
# rubocop:disable Layout/LineLength
233+
is_expected.to contain_postgresql_psql('default_privileges:test')
234+
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema GRANT ALL ON TABLES TO "test"')
235+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')")
236+
# rubocop:enable Layout/LineLength
237+
end
227238
end
228239
end
229240

@@ -244,12 +255,14 @@ class {'postgresql::server':}
244255
EOS
245256
end
246257

247-
it { is_expected.to compile.with_all_deps }
248-
it { is_expected.to contain_postgresql__server__default_privileges('test') }
249-
it { is_expected.to contain_postgresql__server__role('test') }
250-
it do
251-
is_expected.to contain_postgresql_psql('default_privileges:test') \
252-
.that_requires(['Class[postgresql::server::service]', 'Postgresql::Server::Role[test]'])
258+
if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
259+
it { is_expected.to compile.with_all_deps }
260+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
261+
it { is_expected.to contain_postgresql__server__role('test') }
262+
it do
263+
is_expected.to contain_postgresql_psql('default_privileges:test') \
264+
.that_requires(['Class[postgresql::server::service]', 'Postgresql::Server::Role[test]'])
265+
end
253266
end
254267
end
255268

0 commit comments

Comments
 (0)