Skip to content

Commit

Permalink
Merge pull request #351 from ekohl/fix-tests
Browse files Browse the repository at this point in the history
Rely on voxpupuli-test to mock the service_provider fact
  • Loading branch information
ekohl authored Feb 10, 2024
2 parents 032e65a + a6f941c commit 7500c76
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 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
6 changes: 2 additions & 4 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,8 +20,8 @@
}
end

if os_facts[:service_provider] == 'systemd'
it { is_expected.to raise_error(Puppet::Error, %r{Console Producer is not supported on systemd, because the stdin of the process cannot be redirected}) }
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]') }
it { is_expected.to contain_class('kafka::producer::config').that_comes_before('Class[kafka::producer::service]') }
Expand Down

0 comments on commit 7500c76

Please sign in to comment.