Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
fix spec errors in jenkins_service_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 22, 2018
1 parent f3be6af commit da5b221
Showing 1 changed file with 80 additions and 87 deletions.
167 changes: 80 additions & 87 deletions spec/classes/jenkins_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,101 +1,94 @@
require 'spec_helper'

describe 'jenkins', type: :class do
let(:facts) do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '6.7',
operatingsystemmajrelease: '6'
}
end

context 'service' do
context 'default' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end
on_supported_os.each do |os, facts|
next unless facts[:os]['family'] == 'RedHat'

context 'EL 7' do
let(:facts) do
super().merge(
operatingsystemrelease: '7.1.1503',
operatingsystemmajrelease: '7',
systemd: true
)
context "on #{os} " do
systemd_fact = case facts[:operatingsystemmajrelease]
when '6'
{ systemd: false }
else
{ systemd: true }
end
let :facts do
facts.merge(systemd_fact)
end
let(:service_file) { '/etc/systemd/system/jenkins.service' }
let(:startup_script) { '/usr/lib/jenkins/jenkins-run' }
let(:sysv_file) { '/etc/init.d/jenkins' }

it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: 'systemd'
)
end

it do
is_expected.to contain_file(startup_script).
that_notifies('Service[jenkins]')
end
# XXX the prior_to args check fails under puppet 3.8.7 for unknown
# reasons...
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
it do
is_expected.to contain_transition('stop jenkins service').with(
prior_to: ["File[#{sysv_file}]"]
)
context 'service' do
context 'default' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end
else
it { is_expected.to contain_transition('stop jenkins service') }
end
it do
is_expected.to contain_file(sysv_file).
with(
ensure: 'absent',
selinux_ignore_defaults: true
).
that_comes_before('Systemd::Unit_file[jenkins.service]')
end
it do
is_expected.to contain_systemd__unit_file('jenkins.service').
that_notifies('Service[jenkins]')
end
end

context 'EL 6' do
let(:facts) do
super().merge(
operatingsystemrelease: '6.6',
operatingsystemmajrelease: '6',
systemd: false
)
end
case facts[:os]['release']['major']
when '7'
context 'EL 7' do
let(:service_file) { '/etc/systemd/system/jenkins.service' }
let(:startup_script) { '/usr/lib/jenkins/jenkins-run' }
let(:sysv_file) { '/etc/init.d/jenkins' }

it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: nil
)
end
end
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true,
provider: 'systemd'
)
end

context 'managing service' do
let(:params) { { service_ensure: 'stopped', service_enable: false } }
it do
is_expected.to contain_file(startup_script).
that_notifies('Service[jenkins]')
end
# XXX the prior_to args check fails under puppet 3.8.7 for unknown
# reasons...
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
it do
is_expected.to contain_transition('stop jenkins service').with(
prior_to: ["File[#{sysv_file}]"]
)
end
else
it { is_expected.to contain_transition('stop jenkins service') }
end
it do
is_expected.to contain_file(sysv_file).
with(
ensure: 'absent',
selinux_ignore_defaults: true
).
that_comes_before('Systemd::Unit_file[jenkins.service]')
end
it do
is_expected.to contain_systemd__unit_file('jenkins.service').
that_notifies('Service[jenkins]')
end
end
when '6'
context 'EL 6' do
it do
is_expected.to contain_service('jenkins').with(
ensure: 'running',
enable: true
)
end
end

it do
is_expected.to contain_service('jenkins').with(
ensure: 'stopped',
enable: false,
provider: nil
)
context 'managing service' do
let(:params) { { service_ensure: 'stopped', service_enable: false } }

it do
is_expected.to contain_service('jenkins').with(
ensure: 'stopped',
enable: false
)
end
end
end
end
end
end
Expand Down

0 comments on commit da5b221

Please sign in to comment.