Skip to content

Commit

Permalink
wip: mock systemd fact properly
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Aug 18, 2018
1 parent 09c59f6 commit 49f3e69
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ fixtures:
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"archive": "https://github.com/voxpupuli/puppet-archive.git"
"erlang": "git://github.com/garethr/garethr-erlang.git"
"systemd": "https://github.com/camptocamp/puppet-systemd.git"
"systemd":
repo: "https://github.com/bastelfreak/puppet-systemd.git"
branch: limits
symlinks:
"rabbitmq": "#{source_dir}"
28 changes: 14 additions & 14 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'rabbitmq' do
describe 'failing rabbitmq' do
context 'on unsupported distributions' do
let(:facts) do
{
Expand All @@ -12,24 +12,20 @@
expect { catalogue }.to raise_error(Puppet::Error, %r{not supported on an Unsupported})
end
end
end

describe 'working rabbitmq' do

# TODO: get Archlinux & OpenBSD facts from facterdb

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
# Unfortunately still have to set this fact ourselves for supported
# systems as there is no facter run
systemd = (
(facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
(facts[:os]['family'] == 'Debian' && facts[:os]['name'] == 'Ubuntu' &&
facts[:os]['release']['full'] == '16.04') ||
(facts[:os]['family'] == 'Debian' && facts[:os]['name'] == 'Debian' &&
facts[:os]['release']['major'].to_i >= 8) ||
(facts[:os]['family'] == 'Archlinux')
)

facts.merge(systemd: systemd)
p os
p facts
p facts[:facterversion]
let :facts do
p facts
facts.merge(os_specific_facts(facts))
end

packagename = case facts[:osfamily]
Expand Down Expand Up @@ -153,17 +149,21 @@
end

if facts[:systemd]
puts "the systemd fact has this value: #{facts[:systemd].to_s}"
it do
is_expected.to contain_systemd__service_limits('rabbitmq.service').
with_limits('LimitNOFILE' => value).
with_restart_service(false)
end
else
puts "the systemd fact has this value: #{facts[:systemd].to_s}"
it { is_expected.not_to contain_systemd__service_limits('rabbitmq.service') }
end
end
end

exit

[-42, '-42', 'foo', '42'].each do |value|
context "with file_limit => '#{value}'" do
let(:params) { { file_limit: value } }
Expand Down
41 changes: 36 additions & 5 deletions spec/spec_helper_local.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
require 'rspec-puppet-facts'
include RspecPuppetFacts
#require 'rspec-puppet-facts'
#include RspecPuppetFacts
# # Original fact sources:
add_custom_fact :puppetversion, Puppet.version # Facter, but excluded from rspec-puppet-facts
add_custom_fact :rabbitmq_version, '3.6.1' # puppet-rabbitmq
add_custom_fact :erl_ssl_path, '/usr/lib64/erlang/lib/ssl-7.3.3.1/ebin' # puppet-rabbitmq
#add_custom_fact :puppetversion, Puppet.version # Facter, but excluded from rspec-puppet-facts
#add_custom_fact :rabbitmq_version, '3.6.1' # puppet-rabbitmq
#add_custom_fact :erl_ssl_path, '/usr/lib64/erlang/lib/ssl-7.3.3.1/ebin' # puppet-rabbitmq

def os_specific_facts(facts)
case facts[:os]['family']
when 'Archlinux'
{ service_provider: 'systemd', systemd: true }
when 'Debian'
case facts[:os]['release']['major']
when '7'
{ service_provider: 'sysv', systemd: false }
when '8'
{ service_provider: 'systemd', systemd: true }
when '9'
{ service_provider: 'systemd', systemd: true }
when '14.04'
{ service_provider: 'upstart', systemd: false }
when '16.04'
{ service_provider: 'systemd', systemd: true }
when '18.04'
{ service_provider: 'systemd', systemd: true }
end
when 'RedHat'
case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv', systemd: false }
when '7'
{ service_provider: 'systemd', systemd: true }
end
else
{ service_provider: 'systemd', systemd: true }
end
end

0 comments on commit 49f3e69

Please sign in to comment.