packages-formula/test/integration/default/controls/pkgs_spec.rb

132 lines
3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Prepare platform "finger"
platform_finger = system.platform[:finger].split('.').first.to_s
## Some vars
common_packages = %w[
2018-02-12 08:16:03 -03:00
git
less
bc
curl
fail2ban
]
2019-10-03 22:35:30 +01:00
case platform[:family]
when 'redhat'
platform_packages =
case platform_finger
when 'centos-8', 'oraclelinux-8', 'almalinux-8', 'rockylinux-8'
%w[python3-dnf-plugin-versionlock]
else
%w[yum-plugin-versionlock]
end
held_packages = {
# We use this test for held packages in a list,
# with no version (current version).
iotop: ''
}
lock_file = '/etc/yum/pluginconf.d/versionlock.list'
when 'fedora'
platform_packages = ['python3-dnf-plugin-versionlock']
held_packages = {
alien: '8.95-8.fc29',
iotop: '0.6-18.fc29'
}
lock_file = '/etc/dnf/plugins/versionlock.list'
2019-03-06 09:41:23 -03:00
# Adding empty Suse entries, to get tests passing
# Don't know the correct values to add here.
2019-10-03 22:35:30 +01:00
when 'suse'
platform_packages = %w[]
2019-03-06 09:41:23 -03:00
held_packages = {}
lock_file = ''
2019-10-03 22:35:30 +01:00
when 'debian'
platform_packages = %w[]
held_packages = {
alien: '8.95',
2019-03-05 23:19:24 -03:00
# To match also ubuntu16's
iotop: '0.6-'
}
lock_file = '/var/lib/dpkg/status'
2019-12-08 03:23:49 +00:00
when 'linux'
case platform[:name]
when 'arch'
platform_packages = %w[ruby]
held_packages = {}
lock_file = ''
2021-02-10 14:56:43 +00:00
when 'gentoo'
# Empty for now: The `package` resource is not supported on your OS yet.
platform_packages = %w[]
held_packages = {}
lock_file = ''
2019-12-08 03:23:49 +00:00
end
end
# FIXME: - not testing Held packages
2019-08-13 19:16:06 +02:00
held_packages = {}
2019-10-03 22:35:30 +01:00
unheld_packages = (common_packages + platform_packages).flatten.uniq
all_packages = (unheld_packages + held_packages.keys.map(&:to_s)).flatten.uniq
### WANTED/REQUIRED/HELD
control 'Wanted/Required/Held packages' do
title 'should be installed'
all_packages.each do |p|
describe package(p) do
it { should be_installed }
end
2018-02-12 08:16:03 -03:00
end
end
### WANTED UNHELD
control 'Wanted packages' do
title 'should NOT be marked as hold'
unheld_packages.each do |p, v|
2019-10-03 22:35:30 +01:00
case platform[:family]
when 'redhat', 'fedora'
match_string = "#{p}-.*#{v}"
describe file(lock_file) do
its('content') { should_not match(match_string) }
end
2019-10-03 22:35:30 +01:00
when 'debian'
match_string = "^Package: #{p}\nStatus: install ok installed"
describe file(lock_file) do
its('content') { should match(match_string) }
end
end
end
end
### HELD
control 'Held packages' do
title 'should be marked as hold'
held_packages.each do |p, v|
2019-10-03 22:35:30 +01:00
case platform[:family]
when 'redhat', 'fedora'
match_string = "#{p}-.*#{v}"
2019-10-03 22:35:30 +01:00
when 'debian'
match_string = "^Package: #{p}\nStatus: hold ok "\
"installed\nP.*\nS.*\nI.*\nM.*\nA.*\nVersion: #{v}"
end
describe file(lock_file) do
its('content') { should match(match_string) }
end
end
end
### UNWANTED
control 'Unwanted packages' do
title 'should be uninstalled'
%w[
avahi-daemon
].each do |p|
describe package(p) do
it { should_not be_installed }
end
2018-02-12 08:16:03 -03:00
end
end