Skip to content

Commit

Permalink
Cleanup unit tests
Browse files Browse the repository at this point in the history
It's not required to explicitly set the service_provider here.
rspec-puppet-facts does that for us.
  • Loading branch information
bastelfreak committed Oct 29, 2024
1 parent f866cbe commit ccb8431
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
require 'spec_helper'

describe 'consul' do
on_supported_os.each do |os, facts|
next unless facts[:kernel] == 'Linux'
on_supported_os.each do |os, os_facts|
next unless os_facts[:kernel] == 'Linux'

puts "on #{os}"
context "on #{os}" do
provider = case facts[:os]['family']
when 'Archlinux'
{ service_provider: 'systemd' }
when 'Debian'
{ service_provider: 'systemd' }
when 'RedHat'
{ service_provider: 'systemd' }
when 'windows'
{ service_provider: 'unmanaged' }
when 'FreeBSD'
{ service_provider: 'freebsd' }
else
{ service_provider: 'systemd' }
end
facts = facts.merge(provider)
let(:facts) do
facts
os_facts
end

it { is_expected.to compile.with_all_deps }
Expand Down Expand Up @@ -82,7 +67,7 @@
}
end

case facts[:os]['family']
case os_facts[:os]['family']
when 'Debian'
it { is_expected.not_to contain_apt__source('HashiCorp') }
when 'RedHat'
Expand All @@ -98,7 +83,7 @@
}
end

case facts[:os]['family']
case os_facts[:os]['family']
when 'Debian'
it { is_expected.not_to contain_apt__source('HashiCorp') }
when 'RedHat'
Expand All @@ -107,15 +92,15 @@
end

# hashicorp repo is not supported on Arch Linux/SLES
context 'When asked to manage the repo and to install as package', unless: %w[Archlinux SLES Suse].include?(facts[:os]['family']) do
context 'When asked to manage the repo and to install as package', unless: %w[Archlinux SLES Suse].include?(os_facts[:os]['family']) do
let(:params) do
{
install_method: 'package',
manage_repo: true
}
end

case facts[:os]['family']
case os_facts[:os]['family']
when 'Debian'
it { is_expected.to contain_apt__source('HashiCorp') }
when 'RedHat'
Expand Down Expand Up @@ -181,9 +166,9 @@

context 'When installing by archive via URL and current version is already installed' do
let(:facts) do
facts.merge({
consul_version: '1.16.3'
})
os_facts.merge({
consul_version: '1.16.3'
})
end

it { is_expected.to contain_archive('/opt/consul/archives/consul-1.16.3.zip').with(source: 'https://releases.hashicorp.com/consul/1.16.3/consul_1.16.3_linux_amd64.zip') }
Expand Down Expand Up @@ -606,7 +591,7 @@
it { is_expected.not_to contain_file('/etc/systemd/system/consul.service') }
end

case facts[:os]['family']
case os_facts[:os]['family']
when 'RedHat', 'Archlinux', 'Debian'
context 'On a modern OS' do
it { is_expected.to contain_class('consul').with_init_style('systemd') }
Expand Down

0 comments on commit ccb8431

Please sign in to comment.