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
part of modulesync updated
  • Loading branch information
Roberto Valentini committed Apr 3, 2024
1 parent c4785ff commit 6744399
Show file tree
Hide file tree
Showing 38 changed files with 356 additions and 521 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'
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

name: CI

on: pull_request
on:
pull_request: {}
push:
branches:
- main
- master

concurrency:
group: ${{ github.ref_name }}
Expand All @@ -13,6 +18,6 @@ concurrency:
jobs:
puppet:
name: Puppet
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2
with:
pidfile_workaround: 'false'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
release:
name: Release
uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1
uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v2
with:
allowed_owner: 'voxpupuli'
secrets:
Expand Down
12 changes: 5 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

group :test do
gem 'voxpupuli-test', '~> 5.0', :require => false
gem 'voxpupuli-test', '~> 7.0', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
gem 'puppet_metadata', '~> 1.0', :require => false
gem 'puppet_metadata', '~> 3.5', :require => false
end

group :development do
Expand All @@ -16,19 +16,17 @@ group :development do
end

group :system_tests do
gem 'voxpupuli-acceptance', '~> 1.0', :require => false
gem 'voxpupuli-acceptance', '~> 3.0', :require => false
end

group :release do
gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5'
gem 'voxpupuli-release', '>= 1.2.0', :require => false
gem 'puppet-strings', '>= 2.2', :require => false
gem 'voxpupuli-release', '>= 3.0', :require => false
end

gem 'rake', :require => false
gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test]

puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0'
puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 7.24'
gem 'puppet', puppetversion, :require => false, :groups => [:test]

# vim: syntax=ruby
36 changes: 4 additions & 32 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ end
begin
require 'voxpupuli/release/rake_tasks'
rescue LoadError
begin
require 'puppetlabs_spec_helper/rake_tasks'
rescue LoadError
end
end

desc "Run main 'test' task and report merged results to coveralls"
Expand All @@ -37,36 +41,4 @@ task test_with_coveralls: [:test] do
end
end

desc 'Generate REFERENCE.md'
task :reference, [:debug, :backtrace] do |t, args|
patterns = ''
Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace])
end

begin
require 'github_changelog_generator/task'
require 'puppet_blacksmith'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
metadata = Blacksmith::Modulefile.new
config.future_release = "v#{metadata.version}" if metadata.version =~ /^\d+\.\d+.\d+$/
config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module."
config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog}
config.user = 'voxpupuli'
config.project = metadata.metadata['name']
end

# Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715
require 'rbconfig'
if RbConfig::CONFIG['host_os'] =~ /linux/
task :changelog do
puts 'Fixing line endings...'
changelog_file = File.join(__dir__, 'CHANGELOG.md')
changelog_txt = File.read(changelog_file)
new_contents = changelog_txt.gsub(%r{\r\n}, "\n")
File.open(changelog_file, "w") {|file| file.puts new_contents }
end
end

rescue LoadError
end
# vim: syntax=ruby
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: 2 additions & 0 deletions lib/puppet/type/rabbitmq_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def munge_value(value)
return value if value(:autoconvert) == :false

value.each do |k, v|
next if v.is_a?(Array)

value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z}
end
value
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
138 changes: 63 additions & 75 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 }
it { is_expected.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 @@ -127,26 +115,26 @@ class { 'rabbitmq':
end

describe port(25_672) do
xit 'Is on 55672 instead on older rmq versions' do
xit 'Is on 55672 instead on older rmq versions' do # rubocop:disable RSpec/PendingWithoutReason
is_expected.to be_listening.on('0.0.0.0').with('tcp')
end
end
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 @@ -162,30 +150,30 @@ class { 'rabbitmq':
# This listens on all interfaces regardless of these settings

describe port(25_672) do
xit 'Is on 55672 instead on older rmq versions' do
xit 'Is on 55672 instead on older rmq versions' do # rubocop:disable RSpec/PendingWithoutReason
is_expected.to be_listening.on('0.0.0.0').with('tcp')
end
end
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 All @@ -227,7 +215,7 @@ class { 'rabbitmq':
end

describe port(25_672) do
xit 'Is on 55672 instead on older rmq versions' do
xit 'Is on 55672 instead on older rmq versions' do # rubocop:disable RSpec/PendingWithoutReason
is_expected.to be_listening.on('0.0.0.0').with('tcp')
end
end
Expand Down
Loading

0 comments on commit 6744399

Please sign in to comment.