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

Add apt::mark defined type #879

Merged
merged 1 commit into from
Sep 30, 2019
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
24 changes: 24 additions & 0 deletions manifests/mark.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# defined typeapt::mark
#
# @param setting
# auto, manual, hold, unhold
# specifies the behavior of apt in case of no more dependencies installed
# https://manpages.debian.org/sretch/apt/apt-mark.8.en.html
#
define apt::mark (
Enum['auto','manual','hold','unhold'] $setting,
){
case $setting {
'unhold': {
$unless_cmd = undef
}
default: {
$unless_cmd = "/usr/bin/apt-mark showm${setting} ${title} | /bin/fgrep -qs ${title}"
}
}
exec { "/usr/bin/apt-mark ${setting} ${title}":
onlyif => "/usr/bin/dpkg -l ${title}",
unless => $unless_cmd,
}
}

40 changes: 40 additions & 0 deletions spec/defines/mark_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

describe 'apt::mark', type: :define do
let :title do
'my_source'
end

let :facts do
{
os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
lsbdistid: 'Debian',
lsbdistcodename: 'jessie',
osfamily: 'Debian',
}
end

context 'with correct seting' do
let :params do
{
'setting' => 'manual',
}
end

it {
is_expected.to contain_exec('/usr/bin/apt-mark manual my_source')
}
end

describe 'with wrong setting' do
let :params do
{
'setting' => 'foobar',
}
end

it do
is_expected.to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'})
end
end
end