}
}
- if is_hash($pin) {
+ if $pin =~ Hash {
$_pin = $pin
- } elsif is_numeric($pin) or is_string($pin) {
+ } elsif $pin =~ Numeric or $pin =~ String {
# apt::source defaults to pinning to origin, but we should pin to release
# for backports
$_pin = {
fail('This module only works on Debian or derivatives like Ubuntu')
}
- $frequency_options = ['always','daily','weekly','reluctantly']
-
if $update['frequency'] {
- validate_re($update['frequency'], $frequency_options)
+ assert_type(
+ Enum['always','daily','weekly','reluctantly'],
+ $update['frequency'],
+ )
}
if $update['timeout'] {
assert_type(Integer, $update['timeout'])
$_purge = merge($::apt::purge_defaults, $purge)
if $proxy['ensure'] {
- validate_re($proxy['ensure'], ['file', 'present', 'absent'])
+ assert_type(Enum['file', 'present', 'absent'], $proxy['ensure'])
}
if $proxy['host'] {
assert_type(String, $proxy['host'])
Optional[String] $options = undef,
) {
- validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
+ assert_type(
+ Pattern[
+ /\A(0x)?[0-9a-fA-F]{8}\Z/,
+ /\A(0x)?[0-9a-fA-F]{16}\Z/,
+ /\A(0x)?[0-9a-fA-F]{40}\Z/,
+ ], $id)
if $source {
- validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
+ assert_type(Pattern[/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/], $source)
}
if $server {
- validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
+ assert_type(Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/], $server)
}
case $ensure {
# Read the manpage 'apt_preferences(5)', especially the chapter
# 'The Effect of APT Preferences' to understand the following logic
# and the difference between specific and general form
- if is_array($packages) {
+ if $packages =~ Array {
$packages_string = join($packages, ' ')
} else {
$packages_string = $packages
$setting_type = $title_array[0]
$base_name = join(delete_at($title_array, 0), '-')
- validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
+ assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
+ fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
+ }
- unless is_integer($priority) {
+ if $priority !~ Integer {
# need this to allow zero-padded priority.
- validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
+ assert_type(Pattern[/^\d+$/], $priority) |$a, $b| {
+ fail('apt::setting priority must be an integer or a zero-padded integer')
+ }
}
if ($setting_type == 'list') or ($setting_type == 'pref') {
# source.pp
# add an apt source
define apt::source(
- Optional[String] $location = undef,
- String $comment = $name,
- String $ensure = present,
- Optional[String] $release = undef,
- String $repos = 'main',
- Optional[Variant[Hash]] $include = {},
- Optional[Variant[String, Hash]] $key = undef,
- $pin = undef,
- Optional[String] $architecture = undef,
- Boolean $allow_unsigned = false,
- Boolean $notify_update = true,
+ Optional[String] $location = undef,
+ String $comment = $name,
+ String $ensure = present,
+ Optional[String] $release = undef,
+ String $repos = 'main',
+ Optional[Variant[Hash]] $include = {},
+ Optional[Variant[String, Hash]] $key = undef,
+ Optional[Variant[Hash, Numeric, String]] $pin = undef,
+ Optional[String] $architecture = undef,
+ Boolean $allow_unsigned = false,
+ Boolean $notify_update = true,
) {
# This is needed for compat with 1.8.x
$includes = merge($::apt::include_defaults, $include)
if $key {
- if is_hash($key) {
+ if $key =~ Hash {
unless $key['id'] {
fail('key hash must contain at least an id entry')
}
$_key = merge($::apt::source_key_defaults, $key)
} else {
- validate_legacy(String, 'validate_string', $key)
- $_key = { 'id' => $key }
+ $_key = { 'id' => assert_type(String[1], $key) }
}
}
}
if $pin {
- if is_hash($pin) {
+ if $pin =~ Hash {
$_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
- } elsif (is_numeric($pin) or is_string($pin)) {
+ } elsif ($pin =~ Numeric or $pin =~ String) {
$url_split = split($location, '[:\/]+')
$host = $url_split[1]
$_pin = {
# We do not want to remove keys when the source is absent.
if $key and ($ensure == 'present') {
- if is_hash($_key) {
+ if $_key =~ Hash {
apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
ensure => present,
id => $_key['id'],
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
context 'exceed character url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect protocol for url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'missing port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url ending with a dot' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url begin with a dash' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'invalid key' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{does not match})
+ expect { subject.call } .to raise_error(%r{expects a match})
end
end
context 'exceed character url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect protocol for url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'missing port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url ending with a dot' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url begin with a dash' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'invalid key' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{does not match})
+ expect { subject.call }.to raise_error(%r{expects a match})
end
end
it do
expect {
subject.call
- }.to raise_error(Puppet::Error, %r{invalid value for pin})
+ }.to raise_error(Puppet::Error, %r{expects a value})
end
end