Skip to content

Commit 02d20d6

Browse files
committed
Refactor grant spec
1 parent ebaf270 commit 02d20d6

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

spec/unit/defines/server/grant_spec.rb

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"class {'postgresql::server':}"
3030
end
3131

32+
it { is_expected.to compile.with_all_deps }
3233
it { is_expected.to contain_postgresql__server__grant('test') }
3334
end
3435

@@ -46,13 +47,13 @@
4647
"class {'postgresql::server':}"
4748
end
4849

50+
it { is_expected.to compile.with_all_deps }
4951
it { is_expected.to contain_postgresql__server__grant('test') }
50-
it { is_expected.to contain_postgresql_psql('grant:test').with(
51-
{
52-
'command' => /GRANT USAGE ON SEQUENCE "test" TO\s* "test"/m,
53-
'unless' => /SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)/m,
54-
}
55-
) }
52+
it do
53+
is_expected.to contain_postgresql_psql('grant:test'). \
54+
with_command(/GRANT USAGE ON SEQUENCE "test" TO\s* "test"/m). \
55+
with_unless(/SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)/m)
56+
end
5657
end
5758

5859
context 'SeQuEnCe case insensitive object_type match' do
@@ -69,13 +70,13 @@
6970
"class {'postgresql::server':}"
7071
end
7172

73+
it { is_expected.to compile.with_all_deps }
7274
it { is_expected.to contain_postgresql__server__grant('test') }
73-
it { is_expected.to contain_postgresql_psql('grant:test').with(
74-
{
75-
'command' => /GRANT USAGE ON SEQUENCE "test" TO\s* "test"/m,
76-
'unless' => /SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)/m,
77-
}
78-
) }
75+
it do
76+
is_expected.to contain_postgresql_psql('grant:test'). \
77+
with_command(/GRANT USAGE ON SEQUENCE "test" TO\s* "test"/m). \
78+
with_unless(/SELECT 1 WHERE has_sequence_privilege\('test',\s* 'test', 'USAGE'\)/m)
79+
end
7980
end
8081

8182
context 'all sequences' do
@@ -93,13 +94,13 @@
9394
"class {'postgresql::server':}"
9495
end
9596

97+
it { is_expected.to compile.with_all_deps }
9698
it { is_expected.to contain_postgresql__server__grant('test') }
97-
it { is_expected.to contain_postgresql_psql('grant:test').with(
98-
{
99-
'command' => /GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"/m,
100-
'unless' => /SELECT 1 FROM \(\s*SELECT sequence_name\s* FROM information_schema\.sequences\s* WHERE sequence_schema='public'\s* EXCEPT DISTINCT\s* SELECT object_name as sequence_name\s* FROM .* WHERE .*grantee='test'\s* AND object_schema='public'\s* AND privilege_type='USAGE'\s*\) P\s* HAVING count\(P\.sequence_name\) = 0/m,
101-
}
102-
) }
99+
it do
100+
is_expected.to contain_postgresql_psql('grant:test'). \
101+
with_command(/GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"/m). \
102+
with_unless(/SELECT 1 FROM \(\s*SELECT sequence_name\s* FROM information_schema\.sequences\s* WHERE sequence_schema='public'\s* EXCEPT DISTINCT\s* SELECT object_name as sequence_name\s* FROM .* WHERE .*grantee='test'\s* AND object_schema='public'\s* AND privilege_type='USAGE'\s*\) P\s* HAVING count\(P\.sequence_name\) = 0/m)
103+
end
103104
end
104105

105106
context "with specific db connection settings - default port" do
@@ -116,8 +117,13 @@
116117
"class {'postgresql::server':}"
117118
end
118119

120+
it { is_expected.to compile.with_all_deps }
119121
it { is_expected.to contain_postgresql__server__grant('test') }
120-
it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1' } ).with_port( 5432 ) }
122+
it do
123+
is_expected.to contain_postgresql_psql("grant:test"). \
124+
with_connect_settings( { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1' } ). \
125+
with_port(5432)
126+
end
121127
end
122128

123129
context "with specific db connection settings - including port" do
@@ -135,8 +141,9 @@
135141
"class {'postgresql::server':}"
136142
end
137143

144+
it { is_expected.to compile.with_all_deps }
138145
it { is_expected.to contain_postgresql__server__grant('test') }
139-
it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1','PGPORT' => '1234' } ) }
146+
it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' } ) }
140147
end
141148

142149
context "with specific db connection settings - port overriden by explicit parameter" do
@@ -155,8 +162,13 @@
155162
"class {'postgresql::server':}"
156163
end
157164

165+
it { is_expected.to compile.with_all_deps }
158166
it { is_expected.to contain_postgresql__server__grant('test') }
159-
it { is_expected.to contain_postgresql_psql("grant:test").with_connect_settings( { 'PGHOST' => 'postgres-db-server','DBVERSION' => '9.1','PGPORT' => '1234' } ).with_port( '5678' ) }
167+
it do
168+
is_expected.to contain_postgresql_psql("grant:test"). \
169+
with_connect_settings( { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' } ). \
170+
with_port( '5678' )
171+
end
160172
end
161173

162174
context 'with specific schema name' do
@@ -174,13 +186,13 @@
174186
"class {'postgresql::server':}"
175187
end
176188

189+
it { is_expected.to compile.with_all_deps }
177190
it { is_expected.to contain_postgresql__server__grant('test') }
178-
it { is_expected.to contain_postgresql_psql('grant:test').with(
179-
{
180-
'command' => /GRANT ALL ON TABLE "myschema"."mytable" TO\s* "test"/m,
181-
'unless' => /SELECT 1 WHERE has_table_privilege\('test',\s*'myschema.mytable', 'INSERT'\)/m,
182-
}
183-
) }
191+
it do
192+
is_expected.to contain_postgresql_psql('grant:test'). \
193+
with_command(/GRANT ALL ON TABLE "myschema"."mytable" TO\s* "test"/m). \
194+
with_unless(/SELECT 1 WHERE has_table_privilege\('test',\s*'myschema.mytable', 'INSERT'\)/m)
195+
end
184196
end
185197

186198
context 'invalid object_type' do

0 commit comments

Comments
 (0)