Skip to content

Commit

Permalink
Rely on voxpupuli-test to mock the service_provider fact
Browse files Browse the repository at this point in the history
Custom facts in rspec-puppet-facts are strings, not symbols. This is
inconsistent with other facts and confusing and will be fixed in the
next major version of rspec-puppet-facts.
  • Loading branch information
ekohl committed Feb 10, 2024
1 parent 9041c35 commit a6f941c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
10 changes: 4 additions & 6 deletions spec/classes/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
describe 'kafka::broker', type: :class do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
os_facts = os_facts.merge({ service_provider: 'systemd' })

let(:facts) do
os_facts
end
Expand Down Expand Up @@ -60,7 +58,7 @@
end

context 'defaults' do
if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to contain_file('/etc/init.d/kafka').with_ensure('absent') }
it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=} }
it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=} }
Expand All @@ -74,7 +72,7 @@
context 'limit_nofile set' do
let(:params) { super().merge(limit_nofile: '65536') }

if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=65536$} }
else
it { is_expected.to contain_file('/etc/init.d/kafka').with_content %r{ulimit -n 65536$} }
Expand All @@ -84,14 +82,14 @@
context 'limit_core set' do
let(:params) { super().merge(limit_core: 'infinity') }

if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=infinity$} }
else
it { is_expected.to contain_file('/etc/init.d/kafka').with_content %r{ulimit -c infinity$} }
end
end

context 'service_requires set', if: os_facts[:service_provider] == 'systemd' do
context 'service_requires set', if: os_facts['service_provider'] == 'systemd' do
let(:params) { super().merge(service_requires: ['dummy.target']) }

it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^After=dummy\.target$} }
Expand Down
4 changes: 1 addition & 3 deletions spec/classes/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
describe 'kafka::consumer', type: :class do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
os_facts = os_facts.merge({ service_provider: 'systemd' })

let(:facts) do
os_facts
end
Expand Down Expand Up @@ -53,7 +51,7 @@

describe 'kafka::consumer::service' do
context 'defaults' do
if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to contain_file('/etc/systemd/system/kafka-consumer.service') }
else
it { is_expected.to contain_file('/etc/init.d/kafka-consumer') }
Expand Down
4 changes: 1 addition & 3 deletions spec/classes/mirror_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
describe 'kafka::mirror', type: :class do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
os_facts = os_facts.merge({ service_provider: 'systemd' })

let(:facts) do
os_facts
end
Expand Down Expand Up @@ -50,7 +48,7 @@

describe 'kafka::mirror::service' do
context 'defaults' do
if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to contain_file('/etc/init.d/kafka-mirror').with_ensure('absent') }
it { is_expected.to contain_file('/etc/systemd/system/kafka-mirror.service').with_content %r{/opt/kafka/config/(?=.*consumer)|(?=.*producer).propertie} }
else
Expand Down
4 changes: 1 addition & 3 deletions spec/classes/producer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
describe 'kafka::producer', type: :class do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
os_facts = os_facts.merge({ service_provider: 'systemd' })

let(:facts) do
os_facts
end
Expand All @@ -22,7 +20,7 @@
}
end

if os_facts[:service_provider] == 'systemd'
if os_facts['service_provider'] == 'systemd'
it { is_expected.to compile.and_raise_error(%r{Console Producer is not supported on systemd, because the stdin of the process cannot be redirected}) }
else
it { is_expected.to contain_class('kafka::producer::install').that_comes_before('Class[kafka::producer::config]') }
Expand Down

0 comments on commit a6f941c

Please sign in to comment.