From d8a93f0568cc5a655e1b68da52e071eaf977f097 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Mon, 29 Jan 2024 17:22:32 +0000 Subject: [PATCH] test: add tests for not reloading service --- spec/defines/dropin_file_spec.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spec/defines/dropin_file_spec.rb b/spec/defines/dropin_file_spec.rb index 28df2e07..57b423e3 100644 --- a/spec/defines/dropin_file_spec.rb +++ b/spec/defines/dropin_file_spec.rb @@ -2,6 +2,9 @@ require 'spec_helper' +RSpec::Matchers.define_negated_matcher :that_doesnt_notify, :that_notifies +RSpec::Matchers.define_negated_matcher :that_doesnt_subscribe_to, :that_subscribes_to + describe 'systemd::dropin_file' do context 'supported operating systems' do on_supported_os.each do |os, facts| @@ -69,10 +72,31 @@ it { is_expected.to compile.with_all_deps } it { is_expected.to contain_service('myservice').that_subscribes_to("File[#{filename}]") } - it { is_expected.to contain_systemd__daemon_reload(params[:unit]).that_notifies('Service[myservice]') } + it { is_expected.to contain_systemd__daemon_reload(params[:unit]).that_comes_before('Service[myservice]') } + it { is_expected.to contain_systemd__daemon_reload(params[:unit]).that_doesnt_notify('Service[myservice]') } end end + context 'doesn\'t notify services' do + let(:params) do + super().merge(notify_service: false) + end + let(:filename) { "/etc/systemd/system/#{params[:unit]}.d/#{title}" } + let(:pre_condition) do + <<-PUPPET + service { ['test', 'test.service']: + } + PUPPET + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_service('test').that_doesnt_subscribe_to("File[#{filename}]") } + it { is_expected.to contain_service('test.service').that_doesnt_subscribe_to("File[#{filename}]") } + it { is_expected.to contain_service('test').that_doesnt_subscribe_to("Systemd::Daemon_reload[#{params[:unit]}]") } + it { is_expected.to contain_service('test.service').that_doesnt_subscribe_to("Systemd::Daemon_reload[#{params[:unit]}]") } + end + + context 'with selinux_ignore_defaults set to true' do let(:params) do super().merge(selinux_ignore_defaults: true)