Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor specs #100

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,10 @@
"operatingsystemrelease": [
"12.04",
"14.04",
"15.04",
"15.10",
"16.04",
"16.10",
"17.04"
]
},
{
"operatingsystem": "Linux Mint",
"operatingsystemrelease": [
"13",
"17.x",
"18.x"
]
}
],
"requirements": [
Expand Down
137 changes: 137 additions & 0 deletions spec/classes/debian_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
require 'spec_helper'

# rubocop:disable Style/RegexpLiteral
describe 'unattended_upgrades' do
let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
let(:file_options) { '/etc/apt/apt.conf.d/10options' }

let(:pre_condition) do
'include ::apt'
end

shared_examples 'Debian specs' do
let(:params) { {} }

it { is_expected.to compile.with_all_deps }

it do
is_expected.to create_file(file_periodic).with(
owner: 'root',
group: 'root',
mode: '0644'
).with_content(
/APT::Periodic::Enable "1";/
).with_content(
/APT::Periodic::BackupArchiveInterval "0";/
).with_content(
/APT::Periodic::BackupLevel "3";/
).with_content(
/APT::Periodic::MaxAge "0";/
).with_content(
/APT::Periodic::MinAge "2";/
).with_content(
/APT::Periodic::MaxSize "0";/
).with_content(
/APT::Periodic::Update-Package-Lists "1";/
).with_content(
/APT::Periodic::Download-Upgradeable-Packages "0";/
).with_content(
/APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";/
).with_content(
/APT::Periodic::Unattended-Upgrade "1";/
).with_content(
/APT::Periodic::AutocleanInterval "0";/
).with_content(
/APT::Periodic::Verbose "0";/
)
end

it do
is_expected.to contain_apt__conf('auto-upgrades').with(
ensure: 'absent'
)
end
it do
is_expected.to create_file(file_options).with(
owner: 'root',
group: 'root',
mode: '0644'
).with_content(
/^Dpkg::Options\s{/
).with_content(
/^\s+\"--force-confdef\";/
).with_content(
/^\s+\"--force-confold\";/
).without_content(
/\"--force-confnew\";/
).without_content(
/\"--force-confmiss\";/
)
end
end

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(fqdn: 'unattended-upgrades.example.com',
path: '/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin:/root/bin')
end

case facts[:operatingsystem]
when 'Debian'
it_behaves_like 'Debian specs'
case facts[:lsbdistcodename]
when 'squeeze'
context 'with defaults on Debian 6 Squeeze' do
it do
is_expected.to create_file(file_unattended).with(
owner: 'root',
group: 'root',
mode: '0644'
).with_content(
# This section varies for different releases
/\Unattended-Upgrade::Allowed-Origins\ {\n
\t"\${distro_id}\ oldoldstable";\n
\t"\${distro_id}\ \${distro_codename}-security";\n
\t"\${distro_id}\ \${distro_codename}-lts";\n
};/x
)
end
end
when 'wheezy'
context 'with defaults on Debian 7 wheezy' do
it do
is_expected.to create_file(file_unattended).with(
owner: 'root',
group: 'root',
mode: '0644'
).with_content(
# This section varies for different releases
/\Unattended-Upgrade::Origins-Pattern\ {\n
\t"origin=Debian,archive=stable,label=Debian-Security";\n
\t"origin=Debian,archive=oldstable,label=Debian-Security";\n
};/x
)
end
end
when 'jessie'
context 'with defaults on Debian 8 Jessie' do
it do
is_expected.to create_file(file_unattended).with(
owner: 'root',
group: 'root',
mode: '0644'
).with_content(
# This section varies for different releases
/\Unattended-Upgrade::Origins-Pattern\ {\n
\t"origin=Debian,codename=\${distro_codename},label=Debian-Security";\n
};/x
)
end
end
end
end
end
end
end
132 changes: 132 additions & 0 deletions spec/classes/other_debians_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require 'spec_helper'
describe 'unattended_upgrades' do
let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
let(:file_options) { '/etc/apt/apt.conf.d/10options' }

let(:pre_condition) do
'include ::apt'
end

context 'with defaults on Raspbian' do
let(:facts) do
{
os: {
name: 'Raspbian',
family: 'Debian',
release: {
full: '8.0'
}
},
osfamily: 'Debian',
lsbdistid: 'Raspbian',
lsbdistcodename: 'jessie',
lsbrelease: '8.0'
}
end

it do
is_expected.to create_file(file_unattended).with(
owner: 'root',
group: 'root',
mode: '0644'
)
end
end

context 'with defaults on Linux Mint 13 Maya' do
let(:facts) do
{
os: {
name: 'LinuxMint',
family: 'Debian',
release: {
full: '13'
}
},
osfamily: 'Debian',
lsbdistid: 'LinuxMint',
lsbdistcodename: 'maya',
lsbdistrelease: '13',
lsbmajdistrelease: '13'
}
end

it do
is_expected.to create_file(file_unattended).with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
).with_content(
# This is the only section that's different for Ubuntu compared to Debian
%r{\Unattended-Upgrade::Allowed-Origins\ {\n
\t"Ubuntu\:precise-security";\n
};}x
)
end
end

context 'with defaults on Linux Mint 17.3 Rosa' do
let(:facts) do
{
os: {
name: 'LinuxMint',
family: 'Debian',
release: {
full: '17.3'
}
},
osfamily: 'Debian',
lsbdistid: 'LinuxMint',
lsbdistcodename: 'rosa',
lsbdistrelease: '17.3',
lsbmajdistrelease: '17'
}
end

it do
is_expected.to create_file(file_unattended).with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
).with_content(
# This is the only section that's different for Ubuntu compared to Debian
%r{\Unattended-Upgrade::Allowed-Origins\ {\n
\t"Ubuntu\:trusty-security";\n
};}x
)
end
end

context 'with defaults on Linux Mint 18 Sarah' do
let(:facts) do
{
os: {
name: 'LinuxMint',
family: 'Debian',
release: {
full: '18'
}
},
osfamily: 'Debian',
lsbdistid: 'LinuxMint',
lsbdistcodename: 'sarah',
lsbdistrelease: '18',
lsbmajdistrelease: '18'
}
end

it do
is_expected.to create_file(file_unattended).with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
).with_content(
# This is the only section that's different for Ubuntu compared to Debian
%r{\Unattended-Upgrade::Allowed-Origins\ {\n
\t"Ubuntu\:xenial-security";\n
};}x
)
end
end
end
Loading