Skip to content

Commit 423dcbf

Browse files
committed
Provide service_provider for all supported OSes
1 parent 833faa8 commit 423dcbf

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

spec/spec_helper_local.rb

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,62 @@ def param(type, title, param)
9292
end
9393
end
9494

95+
# This duplicates spec_helper but we need it for add_custom_fact
96+
include RspecPuppetFacts
97+
# Rough conversion of grepping in the puppet source:
98+
# grep defaultfor lib/puppet/provider/service/*.rb
99+
# See https://github.com/voxpupuli/voxpupuli-test/blob/master/lib/voxpupuli/test/facts.rb
100+
add_custom_fact :service_provider, ->(_os, facts) do
101+
case facts[:osfamily].downcase
102+
when 'archlinux'
103+
'systemd'
104+
when 'darwin'
105+
'launchd'
106+
when 'debian'
107+
'systemd'
108+
when 'freebsd'
109+
'freebsd'
110+
when 'gentoo'
111+
'openrc'
112+
when 'openbsd'
113+
'openbsd'
114+
when 'redhat'
115+
facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'redhat'
116+
when 'suse'
117+
facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat'
118+
when 'windows'
119+
'windows'
120+
else
121+
'init'
122+
end
123+
end
124+
95125
shared_context 'Debian 9' do
96-
let(:facts) { on_supported_os['debian-9-x86_64'].merge(service_provider: 'systemd') }
126+
let(:facts) { on_supported_os['debian-9-x86_64'] }
97127
end
98128

99129
shared_context 'Debian 10' do
100-
let(:facts) { on_supported_os['debian-10-x86_64'].merge(service_provider: 'systemd') }
130+
let(:facts) { on_supported_os['debian-10-x86_64'] }
101131
end
102132

103133
shared_context 'Debian 11' do
104-
let(:facts) { on_supported_os['debian-11-x86_64'].merge(service_provider: 'systemd') }
134+
let(:facts) { on_supported_os['debian-11-x86_64'] }
105135
end
106136

107137
shared_context 'Ubuntu 18.04' do
108-
let(:facts) { on_supported_os['ubuntu-18.04-x86_64'].merge(service_provider: 'systemd') }
138+
let(:facts) { on_supported_os['ubuntu-18.04-x86_64'] }
109139
end
110140

111141
shared_context 'RedHat 6' do
112-
let(:facts) { on_supported_os['redhat-6-x86_64'].merge(service_provider: 'redhat') }
142+
let(:facts) { on_supported_os['redhat-6-x86_64'] }
113143
end
114144

115145
shared_context 'RedHat 7' do
116-
let(:facts) { on_supported_os['redhat-7-x86_64'].merge(service_provider: 'systemd') }
146+
let(:facts) { on_supported_os['redhat-7-x86_64'] }
117147
end
118148

119149
shared_context 'RedHat 8' do
120-
let(:facts) { on_supported_os['redhat-8-x86_64'].merge(service_provider: 'systemd') }
150+
let(:facts) { on_supported_os['redhat-8-x86_64'] }
121151
end
122152

123153
shared_context 'Fedora 33' do

0 commit comments

Comments
 (0)