Skip to content

Commit

Permalink
test: run config and versionlock on every supported OS
Browse files Browse the repository at this point in the history
  • Loading branch information
teluq-pbrideau committed Jul 4, 2024
1 parent 1b5cb9e commit 9d9f4d6
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 235 deletions.
174 changes: 91 additions & 83 deletions spec/defines/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,106 @@
require 'spec_helper'

describe 'yum::config' do
context 'with no parameters' do
let(:title) { 'assumeyes' }
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

it { is_expected.to compile.and_raise_error(%r{expects a value for parameter 'ensure'}) }
end
context 'with no parameters' do
let(:title) { 'assumeyes' }

%w[dnf yum].each do |pkgmgr|
context "when package_provider fact is #{pkgmgr}" do
let(:facts) { { package_provider: pkgmgr } }
it { is_expected.to compile.and_raise_error(%r{expects a value for parameter 'ensure'}) }
end

context 'when ensure is a Boolean' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: true } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
incl: '/etc/yum.conf',
context: '/files/etc/yum.conf/main/',
changes: "set assumeyes '1'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
incl: '/etc/dnf/dnf.conf',
context: '/files/etc/dnf/dnf.conf/main/',
changes: "set assumeyes '1'"
)
%w[dnf yum].each do |pkgmgr|
context "when package_provider fact is #{pkgmgr}" do
let(:facts) do
super().merge({ package_provider: pkgmgr })
end
end
end

context 'ensure is an Integer' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: 0 } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes '0'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes '0'"
)
context 'when ensure is a Boolean' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: true } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
incl: '/etc/yum.conf',
context: '/files/etc/yum.conf/main/',
changes: "set assumeyes '1'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
incl: '/etc/dnf/dnf.conf',
context: '/files/etc/dnf/dnf.conf/main/',
changes: "set assumeyes '1'"
)
end
end
end
end
end

context 'ensure is a comma separated String' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: '1, 2' } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes '1, 2'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes '1, 2'"
)
context 'ensure is an Integer' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: 0 } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes '0'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes '0'"
)
end
end
end
end
end

context 'when ensure is a Sensitive[String]' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: sensitive('secret') } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes 'secret'",
show_diff: false
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes 'secret'",
show_diff: false
)
context 'ensure is a comma separated String' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: '1, 2' } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes '1, 2'"
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes '1, 2'"
)
end
end
end

context 'when ensure is a Sensitive[String]' do
let(:title) { 'assumeyes' }
let(:params) { { ensure: sensitive('secret') } }

it { is_expected.to compile.with_all_deps }

it 'contains an Augeas resource with the correct changes' do
case pkgmgr
when 'yum'
is_expected.to contain_augeas("yum.conf_#{title}").with(
changes: "set assumeyes 'secret'",
show_diff: false
)
else
is_expected.to contain_augeas("dnf.conf_#{title}").with(
changes: "set assumeyes 'secret'",
show_diff: false
)
end
end
end
end
end
Expand Down
Loading

0 comments on commit 9d9f4d6

Please sign in to comment.