Skip to content

Commit b444f3b

Browse files
author
Roberto Valentini
committed
Fix Test
initial refactoring of acceptance port test to rspec-mock remove unused erlang module from fixture bump dependency version user facts['service_provider] instead facts[systemd]
1 parent 4bf82ef commit b444f3b

39 files changed

+843
-1016
lines changed

.fixtures.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ fixtures:
33
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
44
apt: 'https://github.com/puppetlabs/puppetlabs-apt'
55
archive: 'https://github.com/voxpupuli/puppet-archive'
6-
erlang: 'https://github.com/garethr/garethr-erlang'
76
systemd: 'https://github.com/voxpupuli/puppet-systemd'
87
yumrepo_core: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core'

lib/facter/rabbitmq_nodename.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if Facter::Util::Resolution.which('rabbitmqctl')
66
rabbitmq_nodename = Facter::Core::Execution.execute('rabbitmqctl status 2>&1')
77
begin
8-
%r{^Status of node '?([\w.\-]+@[\w.\-]+)'?}.match(rabbitmq_nodename)[1]
8+
%r{^Status of node '?([\w.-]+@[\w.-]+)'?}.match(rabbitmq_nodename)[1]
99
rescue StandardError
1010
Facter.debug("Error: rabbitmq_nodename facter failed. Output was #{rabbitmq_nodename}")
1111
end

manifests/config.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
default: {}
235235
}
236236
237-
if $facts['systemd'] { # systemd fact provided by systemd module
237+
if $facts['service_provider'] == 'systemd' { # systemd fact provided by systemd module
238238
systemd::service_limits { "${service_name}.service":
239239
selinux_ignore_defaults => ($facts['os']['family'] == 'RedHat'),
240240
limits => {

manifests/service.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
hasrestart => true,
2828
name => $service_name,
2929
}
30-
if $facts['systemd'] and defined(Class['systemd::systemctl::daemon_reload']) {
30+
if $facts['service_provider'] == 'systemd' and defined(Class['systemd::systemctl::daemon_reload']) {
3131
Class['systemd::systemctl::daemon_reload'] -> Service['rabbitmq-server']
3232
}
3333
}

metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@
5858
"dependencies": [
5959
{
6060
"name": "puppetlabs/stdlib",
61-
"version_requirement": ">= 4.25.0 < 9.0.0"
61+
"version_requirement": ">= 4.25.0 < 10.0.0"
6262
},
6363
{
6464
"name": "puppet/archive",
65-
"version_requirement": ">= 2.0.0 < 7.0.0"
65+
"version_requirement": ">= 2.0.0 < 8.0.0"
6666
},
6767
{
6868
"name": "puppet/systemd",
69-
"version_requirement": ">= 2.10.0 < 5.0.0"
69+
"version_requirement": ">= 2.10.0 < 7.0.0"
7070
}
7171
],
7272
"tags": [

spec/acceptance/binding_spec.rb

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'rabbitmq_binding:' do
6+
before do
7+
pp = <<-EOS
8+
class { 'rabbitmq':
9+
service_manage => true,
10+
port => 5672,
11+
delete_guest_user => true,
12+
admin_enable => true,
13+
}
14+
-> rabbitmq_user { 'dan':
15+
admin => true,
16+
password => 'bar',
17+
tags => ['monitoring', 'tag1'],
18+
}
19+
-> rabbitmq_user_permissions { 'dan@host1':
20+
configure_permission => '.*',
21+
read_permission => '.*',
22+
write_permission => '.*',
23+
}
24+
rabbitmq_vhost { 'host1':
25+
ensure => present,
26+
}
27+
-> rabbitmq_exchange { 'exchange1@host1':
28+
user => 'dan',
29+
password => 'bar',
30+
type => 'topic',
31+
ensure => present,
32+
}
33+
-> rabbitmq_queue { 'queue1@host1':
34+
user => 'dan',
35+
password => 'bar',
36+
durable => true,
37+
auto_delete => false,
38+
ensure => present,
39+
}
40+
EOS
41+
42+
apply_manifest(pp, catch_failures: true)
43+
end
44+
45+
context 'when using one routing_key' do
46+
it_behaves_like 'an idempotent resource' do
47+
let(:manifest) do
48+
<<-PUPPET
49+
rabbitmq_binding { 'exchange1@queue1@host1':
50+
user => 'dan',
51+
password => 'bar',
52+
destination_type => 'queue',
53+
routing_key => '#',
54+
ensure => present,
55+
}
56+
PUPPET
57+
end
58+
end
59+
60+
it 'binding exist' do
61+
shell('rabbitmqctl list_bindings -q -p host1') do |r|
62+
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#})
63+
expect(r.exit_code).to be_zero
64+
end
65+
end
66+
67+
it 'resource has the queue' do
68+
shell('rabbitmqctl list_queues -q -p host1') do |r|
69+
expect(r.stdout).to match(%r{queue1})
70+
expect(r.exit_code).to be_zero
71+
end
72+
end
73+
end
74+
75+
context 'when using two routing_keys' do
76+
it_behaves_like 'an idempotent resource' do
77+
let(:manifest) do
78+
<<-PUPPET
79+
rabbitmq_binding { 'binding 1':
80+
source => 'exchange1',
81+
destination => 'queue1',
82+
user => 'dan',
83+
vhost => 'host1',
84+
password => 'bar',
85+
destination_type => 'queue',
86+
routing_key => 'test1',
87+
ensure => present,
88+
}
89+
-> rabbitmq_binding { 'binding 2':
90+
source => 'exchange1',
91+
destination => 'queue1',
92+
user => 'dan',
93+
vhost => 'host1',
94+
password => 'bar',
95+
destination_type => 'queue',
96+
routing_key => 'test2',
97+
ensure => present,
98+
}
99+
PUPPET
100+
end
101+
end
102+
103+
it 'resource has the bindings' do
104+
shell('rabbitmqctl list_bindings -q -p host1') do |r|
105+
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1})
106+
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2})
107+
expect(r.exit_code).to be_zero
108+
end
109+
end
110+
111+
it 'puppet resource shows a binding' do
112+
shell('puppet resource rabbitmq_binding') do |r|
113+
expect(r.stdout).to match(%r{source\s+=>\s+'exchange1',})
114+
end
115+
end
116+
end
117+
end

spec/acceptance/class_spec.rb

Lines changed: 60 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
end
1414

1515
context 'default class inclusion' do
16-
let(:pp) do
17-
<<-EOS
18-
class { 'rabbitmq': }
19-
if $facts['os']['family'] == 'RedHat' {
20-
class { 'erlang': epel_enable => true}
21-
Class['erlang'] -> Class['rabbitmq']
22-
}
23-
EOS
16+
it_behaves_like 'an idempotent resource' do
17+
let(:manifest) do
18+
<<-PUPPET
19+
class { 'rabbitmq': }
20+
PUPPET
21+
end
2422
end
2523

26-
it_behaves_like 'an idempotent resource'
27-
2824
describe package(package_name) do
2925
it { is_expected.to be_installed }
3026
end
@@ -49,20 +45,20 @@ class { 'erlang': epel_enable => true}
4945
end
5046

5147
context 'disable and stop service' do
52-
let(:pp) do
53-
<<-EOS
54-
class { 'rabbitmq':
55-
service_ensure => 'stopped',
56-
}
57-
if $facts['os']['family'] == 'RedHat' {
58-
class { 'erlang': epel_enable => true}
59-
Class['erlang'] -> Class['rabbitmq']
60-
}
61-
EOS
48+
it_behaves_like 'an idempotent resource' do
49+
let(:manifest) do
50+
<<-PUPPET
51+
class { 'rabbitmq':
52+
service_ensure => 'stopped',
53+
}
54+
if $facts['os']['family'] == 'RedHat' {
55+
class { 'erlang': epel_enable => true}
56+
Class['erlang'] -> Class['rabbitmq']
57+
}
58+
PUPPET
59+
end
6260
end
6361

64-
it_behaves_like 'an idempotent resource'
65-
6662
describe service(service_name) do
6763
it { is_expected.not_to be_enabled }
6864
it { is_expected.not_to be_running }
@@ -73,21 +69,13 @@ class { 'erlang': epel_enable => true}
7369
it 'runs successfully' do
7470
pp_pre = <<-EOS
7571
class { 'rabbitmq': }
76-
if $facts['os']['family'] == 'RedHat' {
77-
class { 'erlang': epel_enable => true}
78-
Class['erlang'] -> Class['rabbitmq']
79-
}
8072
EOS
8173

8274
pp = <<-EOS
8375
class { 'rabbitmq':
8476
service_manage => false,
8577
service_ensure => 'stopped',
8678
}
87-
if $facts['os']['family'] == 'RedHat' {
88-
class { 'erlang': epel_enable => true}
89-
Class['erlang'] -> Class['rabbitmq']
90-
}
9179
EOS
9280

9381
apply_manifest(pp_pre, catch_failures: true)
@@ -101,19 +89,19 @@ class { 'erlang': epel_enable => true}
10189
end
10290

10391
context 'binding on all interfaces' do
104-
let(:pp) do
105-
<<-EOS
106-
class { 'rabbitmq':
107-
service_manage => true,
108-
port => 5672,
109-
admin_enable => true,
110-
node_ip_address => '0.0.0.0'
111-
}
112-
EOS
92+
it_behaves_like 'an idempotent resource' do
93+
let(:manifest) do
94+
<<-PUPPET
95+
class { 'rabbitmq':
96+
service_manage => true,
97+
port => 5672,
98+
admin_enable => true,
99+
node_ip_address => '0.0.0.0'
100+
}
101+
PUPPET
102+
end
113103
end
114104

115-
it_behaves_like 'an idempotent resource'
116-
117105
describe service(service_name) do
118106
it { is_expected.to be_running }
119107
end
@@ -134,19 +122,19 @@ class { 'rabbitmq':
134122
end
135123

136124
context 'binding to localhost only' do
137-
let(:pp) do
138-
<<-EOS
139-
class { 'rabbitmq':
140-
service_manage => true,
141-
port => 5672,
142-
admin_enable => true,
143-
node_ip_address => '127.0.0.1'
144-
}
145-
EOS
125+
it_behaves_like 'an idempotent resource' do
126+
let(:manifest) do
127+
<<-PUPPET
128+
class { 'rabbitmq':
129+
service_manage => true,
130+
port => 5672,
131+
admin_enable => true,
132+
node_ip_address => '127.0.0.1'
133+
}
134+
PUPPET
135+
end
146136
end
147137

148-
it_behaves_like 'an idempotent resource'
149-
150138
describe service(service_name) do
151139
it { is_expected.to be_running }
152140
end
@@ -169,23 +157,23 @@ class { 'rabbitmq':
169157
end
170158

171159
context 'ssl enabled' do
172-
let(:pp) do
173-
<<-EOS
174-
class { 'rabbitmq':
175-
service_manage => true,
176-
admin_enable => true,
177-
node_ip_address => '0.0.0.0',
178-
ssl_interface => '0.0.0.0',
179-
ssl => true,
180-
ssl_cacert => '/tmp/cacert.crt',
181-
ssl_cert => '/tmp/rabbitmq.crt',
182-
ssl_key => '/tmp/rabbitmq.key',
183-
}
184-
EOS
160+
it_behaves_like 'an idempotent resource' do
161+
let(:manifest) do
162+
<<-PUPPET
163+
class { 'rabbitmq':
164+
service_manage => true,
165+
admin_enable => true,
166+
node_ip_address => '0.0.0.0',
167+
ssl_interface => '0.0.0.0',
168+
ssl => true,
169+
ssl_cacert => '/tmp/cacert.crt',
170+
ssl_cert => '/tmp/rabbitmq.crt',
171+
ssl_key => '/tmp/rabbitmq.key',
172+
}
173+
PUPPET
174+
end
185175
end
186176

187-
it_behaves_like 'an idempotent resource'
188-
189177
describe service(service_name) do
190178
it { is_expected.to be_running }
191179
end
@@ -200,20 +188,20 @@ class { 'rabbitmq':
200188
end
201189

202190
context 'different management_ip_address and node_ip_address' do
203-
let(:pp) do
204-
<<-EOS
191+
it_behaves_like 'an idempotent resource' do
192+
let(:manifest) do
193+
<<-PUPPET
205194
class { 'rabbitmq':
206195
service_manage => true,
207196
port => 5672,
208197
admin_enable => true,
209198
node_ip_address => '0.0.0.0',
210199
management_ip_address => '127.0.0.1'
211200
}
212-
EOS
201+
PUPPET
202+
end
213203
end
214204

215-
it_behaves_like 'an idempotent resource'
216-
217205
describe service(service_name) do
218206
it { is_expected.to be_running }
219207
end

0 commit comments

Comments
 (0)