Skip to content

Commit

Permalink
Fix Test
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Roberto Valentini committed Apr 4, 2024
1 parent 4bf82ef commit b444f3b
Show file tree
Hide file tree
Showing 39 changed files with 843 additions and 1,016 deletions.
1 change: 0 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ fixtures:
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
apt: 'https://github.com/puppetlabs/puppetlabs-apt'
archive: 'https://github.com/voxpupuli/puppet-archive'
erlang: 'https://github.com/garethr/garethr-erlang'
systemd: 'https://github.com/voxpupuli/puppet-systemd'
yumrepo_core: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core'
2 changes: 1 addition & 1 deletion lib/facter/rabbitmq_nodename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if Facter::Util::Resolution.which('rabbitmqctl')
rabbitmq_nodename = Facter::Core::Execution.execute('rabbitmqctl status 2>&1')
begin
%r{^Status of node '?([\w.\-]+@[\w.\-]+)'?}.match(rabbitmq_nodename)[1]
%r{^Status of node '?([\w.-]+@[\w.-]+)'?}.match(rabbitmq_nodename)[1]
rescue StandardError
Facter.debug("Error: rabbitmq_nodename facter failed. Output was #{rabbitmq_nodename}")
end
Expand Down
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
default: {}
}
if $facts['systemd'] { # systemd fact provided by systemd module
if $facts['service_provider'] == 'systemd' { # systemd fact provided by systemd module
systemd::service_limits { "${service_name}.service":
selinux_ignore_defaults => ($facts['os']['family'] == 'RedHat'),
limits => {
Expand Down
2 changes: 1 addition & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
hasrestart => true,
name => $service_name,
}
if $facts['systemd'] and defined(Class['systemd::systemctl::daemon_reload']) {
if $facts['service_provider'] == 'systemd' and defined(Class['systemd::systemctl::daemon_reload']) {
Class['systemd::systemctl::daemon_reload'] -> Service['rabbitmq-server']
}
}
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.25.0 < 9.0.0"
"version_requirement": ">= 4.25.0 < 10.0.0"
},
{
"name": "puppet/archive",
"version_requirement": ">= 2.0.0 < 7.0.0"
"version_requirement": ">= 2.0.0 < 8.0.0"
},
{
"name": "puppet/systemd",
"version_requirement": ">= 2.10.0 < 5.0.0"
"version_requirement": ">= 2.10.0 < 7.0.0"
}
],
"tags": [
Expand Down
117 changes: 117 additions & 0 deletions spec/acceptance/binding_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'rabbitmq_binding:' do
before do
pp = <<-EOS
class { 'rabbitmq':
service_manage => true,
port => 5672,
delete_guest_user => true,
admin_enable => true,
}
-> rabbitmq_user { 'dan':
admin => true,
password => 'bar',
tags => ['monitoring', 'tag1'],
}
-> rabbitmq_user_permissions { 'dan@host1':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
}
rabbitmq_vhost { 'host1':
ensure => present,
}
-> rabbitmq_exchange { 'exchange1@host1':
user => 'dan',
password => 'bar',
type => 'topic',
ensure => present,
}
-> rabbitmq_queue { 'queue1@host1':
user => 'dan',
password => 'bar',
durable => true,
auto_delete => false,
ensure => present,
}
EOS

apply_manifest(pp, catch_failures: true)
end

context 'when using one routing_key' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
rabbitmq_binding { 'exchange1@queue1@host1':
user => 'dan',
password => 'bar',
destination_type => 'queue',
routing_key => '#',
ensure => present,
}
PUPPET
end
end

it 'binding exist' do

Check failure on line 60 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - CentOS 7

rabbitmq_binding: when using one routing_key binding exist Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) expected "\texchange\tqueue1\tqueue\tqueue1\t[]\n" to match /exchange1\sexchange\squeue1\squeue\s#/ Diff: @@ -1 +1 @@ -/exchange1\sexchange\squeue1\squeue\s#/ + exchange queue1 queue queue1 []

Check failure on line 60 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - Debian 10

rabbitmq_binding: when using one routing_key binding exist Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) expected "source_name\tsource_kind\tdestination_name\tdestination_kind\trouting_key\targuments\n\texchange\tqueue1\tqueue\tqueue1\t[]\n" to match /exchange1\sexchange\squeue1\squeue\s#/ Diff: @@ -1,2 +1,3 @@ -/exchange1\sexchange\squeue1\squeue\s#/ +source_name source_kind destination_name destination_kind routing_key arguments + exchange queue1 queue queue1 []

Check failure on line 60 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - Ubuntu 18.04

rabbitmq_binding: when using one routing_key binding exist Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) expected "\texchange\tqueue1\tqueue\tqueue1\t[]\n" to match /exchange1\sexchange\squeue1\squeue\s#/ Diff: @@ -1 +1 @@ -/exchange1\sexchange\squeue1\squeue\s#/ + exchange queue1 queue queue1 []
shell('rabbitmqctl list_bindings -q -p host1') do |r|
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#})
expect(r.exit_code).to be_zero
end
end

it 'resource has the queue' do
shell('rabbitmqctl list_queues -q -p host1') do |r|
expect(r.stdout).to match(%r{queue1})
expect(r.exit_code).to be_zero
end
end
end

context 'when using two routing_keys' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
rabbitmq_binding { 'binding 1':
source => 'exchange1',
destination => 'queue1',
user => 'dan',
vhost => 'host1',
password => 'bar',
destination_type => 'queue',
routing_key => 'test1',
ensure => present,
}
-> rabbitmq_binding { 'binding 2':
source => 'exchange1',
destination => 'queue1',
user => 'dan',
vhost => 'host1',
password => 'bar',
destination_type => 'queue',
routing_key => 'test2',
ensure => present,
}
PUPPET
end
end

it 'resource has the bindings' do

Check failure on line 103 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - CentOS 7

rabbitmq_binding: when using two routing_keys resource has the bindings Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) expected "\texchange\tqueue1\tqueue\tqueue1\t[]\nexchange1\texchange\tqueue1\tqueue\t#\t[]\n" to match /exchange1\sexchange\squeue1\squeue\stest1/ Diff: @@ -1,2 +1,3 @@ -/exchange1\sexchange\squeue1\squeue\stest1/ + exchange queue1 queue queue1 [] +exchange1 exchange queue1 queue # []

Check failure on line 103 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - Debian 10

rabbitmq_binding: when using two routing_keys resource has the bindings Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) expected "source_name\tsource_kind\tdestination_name\tdestination_kind\trouting_key\targuments\n\texchange\tqueue1\tqueue\tqueue1\t[]\nexchange1\texchange\tqueue1\tqueue\t#\t[]\n" to match /exchange1\sexchange\squeue1\squeue\stest1/ Diff: @@ -1,3 +1,5 @@ -/exchange1\sexchange\squeue1\squeue\stest1/ +source_name source_kind destination_name destination_kind routing_key arguments + exchange queue1 queue queue1 [] +exchange1 exchange queue1 queue # []

Check failure on line 103 in spec/acceptance/binding_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - Ubuntu 18.04

rabbitmq_binding: when using two routing_keys resource has the bindings Failure/Error: expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) expected "\texchange\tqueue1\tqueue\tqueue1\t[]\nexchange1\texchange\tqueue1\tqueue\t#\t[]\n" to match /exchange1\sexchange\squeue1\squeue\stest1/ Diff: @@ -1,2 +1,3 @@ -/exchange1\sexchange\squeue1\squeue\stest1/ + exchange queue1 queue queue1 [] +exchange1 exchange queue1 queue # []
shell('rabbitmqctl list_bindings -q -p host1') do |r|
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1})
expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2})
expect(r.exit_code).to be_zero
end
end

it 'puppet resource shows a binding' do
shell('puppet resource rabbitmq_binding') do |r|
expect(r.stdout).to match(%r{source\s+=>\s+'exchange1',})
end
end
end
end
132 changes: 60 additions & 72 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
end

context 'default class inclusion' do
let(:pp) do
<<-EOS
class { 'rabbitmq': }
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq': }
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe package(package_name) do
it { is_expected.to be_installed }
end
Expand All @@ -49,20 +45,20 @@ class { 'erlang': epel_enable => true}
end

context 'disable and stop service' do
let(:pp) do
<<-EOS
class { 'rabbitmq':
service_ensure => 'stopped',
}
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq':
service_ensure => 'stopped',
}
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe service(service_name) do
it { is_expected.not_to be_enabled }

Check failure on line 63 in spec/acceptance/class_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - CentOS 7

rabbitmq class: disable and stop service Service "rabbitmq-server" is expected not to be enabled Failure/Error: it { is_expected.not_to be_enabled } expected Service "rabbitmq-server" not to be enabled
it { is_expected.not_to be_running }

Check failure on line 64 in spec/acceptance/class_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 - CentOS 7

rabbitmq class: disable and stop service Service "rabbitmq-server" is expected not to be running Failure/Error: it { is_expected.not_to be_running } expected Service "rabbitmq-server" not to be running
Expand All @@ -73,21 +69,13 @@ class { 'erlang': epel_enable => true}
it 'runs successfully' do
pp_pre = <<-EOS
class { 'rabbitmq': }
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS

pp = <<-EOS
class { 'rabbitmq':
service_manage => false,
service_ensure => 'stopped',
}
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS

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

context 'binding on all interfaces' do
let(:pp) do
<<-EOS
class { 'rabbitmq':
service_manage => true,
port => 5672,
admin_enable => true,
node_ip_address => '0.0.0.0'
}
EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq':
service_manage => true,
port => 5672,
admin_enable => true,
node_ip_address => '0.0.0.0'
}
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe service(service_name) do
it { is_expected.to be_running }
end
Expand All @@ -134,19 +122,19 @@ class { 'rabbitmq':
end

context 'binding to localhost only' do
let(:pp) do
<<-EOS
class { 'rabbitmq':
service_manage => true,
port => 5672,
admin_enable => true,
node_ip_address => '127.0.0.1'
}
EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq':
service_manage => true,
port => 5672,
admin_enable => true,
node_ip_address => '127.0.0.1'
}
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe service(service_name) do
it { is_expected.to be_running }
end
Expand All @@ -169,23 +157,23 @@ class { 'rabbitmq':
end

context 'ssl enabled' do
let(:pp) do
<<-EOS
class { 'rabbitmq':
service_manage => true,
admin_enable => true,
node_ip_address => '0.0.0.0',
ssl_interface => '0.0.0.0',
ssl => true,
ssl_cacert => '/tmp/cacert.crt',
ssl_cert => '/tmp/rabbitmq.crt',
ssl_key => '/tmp/rabbitmq.key',
}
EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq':
service_manage => true,
admin_enable => true,
node_ip_address => '0.0.0.0',
ssl_interface => '0.0.0.0',
ssl => true,
ssl_cacert => '/tmp/cacert.crt',
ssl_cert => '/tmp/rabbitmq.crt',
ssl_key => '/tmp/rabbitmq.key',
}
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe service(service_name) do
it { is_expected.to be_running }
end
Expand All @@ -200,20 +188,20 @@ class { 'rabbitmq':
end

context 'different management_ip_address and node_ip_address' do
let(:pp) do
<<-EOS
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'rabbitmq':
service_manage => true,
port => 5672,
admin_enable => true,
node_ip_address => '0.0.0.0',
management_ip_address => '127.0.0.1'
}
EOS
PUPPET
end
end

it_behaves_like 'an idempotent resource'

describe service(service_name) do
it { is_expected.to be_running }
end
Expand Down

0 comments on commit b444f3b

Please sign in to comment.