Skip to content

Commit 0af94fd

Browse files
committed
Merge pull request #967 from ekohl/cleanups
Various cleanups
2 parents babe5e4 + 9e5fed2 commit 0af94fd

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

spec/spec_helper_acceptance.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,9 @@
1010

1111
UNSUPPORTED_PLATFORMS = %w[AIX windows Solaris Suse].freeze
1212

13-
# monkey patch to get around apt/forge issue (PUP-8008)
14-
module Beaker::ModuleInstallHelper
15-
include Beaker::DSL
16-
17-
def module_dependencies_from_metadata
18-
metadata = module_metadata
19-
return [] unless metadata.key?('dependencies')
20-
21-
dependencies = []
22-
23-
# get it outta here!
24-
metadata['dependencies'].delete_if { |d| d['name'] == 'puppetlabs/apt' }
25-
26-
metadata['dependencies'].each do |d|
27-
tmp = { module_name: d['name'].sub('/', '-') }
28-
29-
if d.key?('version_requirement')
30-
tmp[:version] = module_version_from_requirement(tmp[:module_name],
31-
d['version_requirement'])
32-
end
33-
dependencies.push(tmp)
34-
end
35-
36-
dependencies
37-
end
38-
end
39-
4013
install_bolt_on(hosts) unless pe_install?
4114
install_module_on(hosts)
4215
install_module_dependencies_on(hosts)
43-
install_module_from_forge_on(hosts, 'puppetlabs/apt', '< 4.2.0')
4416

4517
DEFAULT_PASSWORD = if default[:hypervisor] == 'vagrant'
4618
'vagrant'

spec/unit/defines/server/grant_spec.rb

Lines changed: 55 additions & 24 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 {
51-
is_expected.to contain_postgresql_psql('grant:test').with(
52-
'command' => %r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m,
53-
'unless' => %r{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(%r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m)
55+
.with_unless(%r{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 {
74-
is_expected.to contain_postgresql_psql('grant:test').with(
75-
'command' => %r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m,
76-
'unless' => %r{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(%r{GRANT USAGE ON SEQUENCE "test" TO\s* "test"}m)
78+
.with_unless(%r{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 {
98-
is_expected.to contain_postgresql_psql('grant:test').with(
99-
'command' => %r{GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"}m,
100-
'unless' => %r{SELECT 1 WHERE NOT EXISTS \(\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*\)}m, # rubocop:disable Metrics/LineLength
101-
)
102-
}
99+
it do
100+
is_expected.to contain_postgresql_psql('grant:test')
101+
.with_command(%r{GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO\s* "test"}m)
102+
.with_unless(%r{SELECT 1 WHERE NOT EXISTS \(\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*\)}m) # rubocop:disable Metrics/LineLength
103+
end
103104
end
104105

105106
context 'with specific db connection settings - default port' do
@@ -116,6 +117,7 @@
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') }
120122
it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1').with_port(5432) }
121123
end
@@ -135,6 +137,7 @@
135137
"class {'postgresql::server':}"
136138
end
137139

140+
it { is_expected.to compile.with_all_deps }
138141
it { is_expected.to contain_postgresql__server__grant('test') }
139142
it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') }
140143
end
@@ -155,6 +158,7 @@
155158
"class {'postgresql::server':}"
156159
end
157160

161+
it { is_expected.to compile.with_all_deps }
158162
it { is_expected.to contain_postgresql__server__grant('test') }
159163
it { is_expected.to contain_postgresql_psql('grant:test').with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234').with_port('5678') }
160164
end
@@ -174,13 +178,40 @@
174178
"class {'postgresql::server':}"
175179
end
176180

181+
it { is_expected.to compile.with_all_deps }
177182
it { is_expected.to contain_postgresql__server__grant('test') }
178-
it {
179-
is_expected.to contain_postgresql_psql('grant:test').with(
180-
'command' => %r{GRANT ALL ON TABLE "myschema"."mytable" TO\s* "test"}m,
181-
'unless' => %r{SELECT 1 WHERE has_table_privilege\('test',\s*'myschema.mytable', 'INSERT'\)}m,
182-
)
183-
}
183+
it do
184+
is_expected.to contain_postgresql_psql('grant:test')
185+
.with_command(%r{GRANT ALL ON TABLE "myschema"."mytable" TO\s* "test"}m)
186+
.with_unless(%r{SELECT 1 WHERE has_table_privilege\('test',\s*'myschema.mytable', 'INSERT'\)}m)
187+
end
188+
end
189+
190+
context 'with a role defined' do
191+
let :params do
192+
{
193+
db: 'test',
194+
role: 'test',
195+
privilege: 'all',
196+
object_name: %w[myschema mytable],
197+
object_type: 'table',
198+
}
199+
end
200+
201+
let :pre_condition do
202+
<<-EOS
203+
class {'postgresql::server':}
204+
postgresql::server::role { 'test': }
205+
EOS
206+
end
207+
208+
it { is_expected.to compile.with_all_deps }
209+
it { is_expected.to contain_postgresql__server__grant('test') }
210+
it { is_expected.to contain_postgresql__server__role('test') }
211+
it do
212+
is_expected.to contain_postgresql_psql('grant:test') \
213+
.that_requires('Postgresql::Server::Role[test]')
214+
end
184215
end
185216

186217
context 'invalid object_type' do

spec/unit/defines/server/reassign_owned_by_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class {'postgresql::server':}
3636

3737
it {
3838
is_expected.to contain_postgresql_psql('reassign_owned_by:test:REASSIGN OWNED BY "test_old_role" TO "test_new_role"')
39-
.with('command' => 'REASSIGN OWNED BY "test_old_role" TO "test_new_role"',
40-
'onlyif' => %r{SELECT tablename FROM pg_catalog.pg_tables WHERE\s*schemaname NOT IN \('pg_catalog', 'information_schema'\) AND\s*tableowner = 'test_old_role'.*}m)
39+
.with_command('REASSIGN OWNED BY "test_old_role" TO "test_new_role"')
40+
.with_onlyif(%r{SELECT tablename FROM pg_catalog.pg_tables WHERE\s*schemaname NOT IN \('pg_catalog', 'information_schema'\) AND\s*tableowner = 'test_old_role'.*}m)
4141
.that_requires('Class[postgresql::server]')
4242
}
4343
end

spec/unit/defines/server/role_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@
6161
it { is_expected.to contain_postgresql__server__role('test') }
6262
it 'has create role for "test" user with password as ****' do
6363
is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
64-
.with('command' => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1", 'environment' => 'NEWPGPASSWD=new-pa$s',
65-
'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'", 'port' => '5432',
66-
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
67-
'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
64+
.with_command("CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1")
65+
.with_environment('NEWPGPASSWD=new-pa$s')
66+
.with_unless("SELECT 1 FROM pg_roles WHERE rolname = 'test'")
67+
.with_port(5432)
68+
.with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass')
6869
end
6970
it 'has alter role for "test" user with password as ****' do
7071
is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')

0 commit comments

Comments
 (0)