- 'spec/defines/source_compat_spec.rb'
- 'spec/defines/source_spec.rb'
-# Offense count: 6
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: strict, consistent
-Lint/SymbolConversion:
- Exclude:
- - 'spec/classes/apt_update_spec.rb'
-
# Offense count: 6
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
- 'spec/unit/facter/apt_reboot_required_spec.rb'
- 'spec/unit/puppet/type/apt_key_spec.rb'
-# Offense count: 8
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: be, be_nil
-RSpec/BeNil:
- Exclude:
- - 'spec/unit/facter/apt_dist_package_security_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_package_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_security_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_updates_spec.rb'
- - 'spec/unit/facter/apt_package_security_updates_spec.rb'
- - 'spec/unit/facter/apt_package_updates_spec.rb'
- - 'spec/unit/facter/apt_security_updates_spec.rb'
- - 'spec/unit/facter/apt_updates_spec.rb'
-
# Offense count: 6
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/DescribeClass:
Enabled: false
-# Offense count: 23
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowConsecutiveOneLiners.
-RSpec/EmptyLineAfterExample:
- Exclude:
- - 'spec/acceptance/apt_key_provider_spec.rb'
- - 'spec/acceptance/apt_spec.rb'
- - 'spec/classes/apt_spec.rb'
- - 'spec/defines/key_compat_spec.rb'
- - 'spec/defines/key_spec.rb'
- - 'spec/defines/pin_spec.rb'
- - 'spec/defines/ppa_spec.rb'
- - 'spec/defines/source_spec.rb'
-
-# Offense count: 39
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/EmptyLineAfterExampleGroup:
- Exclude:
- - 'spec/acceptance/apt_key_provider_spec.rb'
- - 'spec/acceptance/init_task_spec.rb'
- - 'spec/classes/apt_backports_spec.rb'
- - 'spec/classes/apt_spec.rb'
- - 'spec/classes/apt_update_spec.rb'
- - 'spec/defines/key_compat_spec.rb'
- - 'spec/defines/key_spec.rb'
- - 'spec/defines/source_spec.rb'
-
-# Offense count: 24
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowConsecutiveOneLiners.
-RSpec/EmptyLineAfterHook:
- Exclude:
- - 'spec/acceptance/apt_key_provider_spec.rb'
- - 'spec/unit/facter/apt_dist_has_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_package_security_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_package_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_security_updates_spec.rb'
- - 'spec/unit/facter/apt_dist_updates_spec.rb'
- - 'spec/unit/facter/apt_has_updates_spec.rb'
- - 'spec/unit/facter/apt_package_security_updates_spec.rb'
- - 'spec/unit/facter/apt_package_updates_spec.rb'
- - 'spec/unit/facter/apt_reboot_required_spec.rb'
- - 'spec/unit/facter/apt_security_updates_spec.rb'
- - 'spec/unit/facter/apt_updates_spec.rb'
- - 'spec/unit/puppet/provider/apt_key_spec.rb'
-
# Offense count: 13
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
it 'add an apt_key resource' do
apply_manifest_twice(ensure_present_pp)
end
+
it 'remove the apt_key resource' do
apply_manifest_twice(ensure_absent_pp)
end
after(:each) do
run_shell('rm /tmp/fake-key.gpg')
end
+
it 'fails' do
apply_manifest(path_bogus_content_pp, expect_failures: true) do |r|
expect(r.stderr).to match(%r{no valid OpenPGP data found})
apply_manifest(refresh_del_key_pp)
apply_manifest(refresh_pp, catch_failures: true)
end
+
context 'when refresh => true' do
it 'updates an expired key' do
apply_manifest(refresh_true_pp)
run_shell(PUPPETLABS_EXP_CHECK_COMMAND.to_s)
end
end
+
context 'when refresh => false' do
it 'does not replace an expired key' do
apply_manifest(refresh_false_pp)
apply_manifest(everything_everything_pp, catch_failures: true)
end
end
+
it 'stills work' do
run_shell('apt-get update')
run_shell('apt-get -y --force-yes upgrade')
expect(result.stdout).to contain(%r{Reading package lists})
end
end
+
describe 'upgrade' do
it 'upgrades packages' do
result = run_bolt_task('apt', 'action' => 'upgrade')
expect(result.stdout).to contain(%r{\d+ upgraded, \d+ newly installed, \d+ to remove and \d+ not upgraded})
end
end
+
describe 'dist-upgrade' do
it 'dist-upgrades packages' do
result = run_bolt_task('apt', 'action' => 'dist-upgrade')
expect(result.stdout).to contain(%r{\d+ upgraded, \d+ newly installed, \d+ to remove and \d+ not upgraded})
end
end
+
describe 'autoremove' do
it 'autoremoves obsolete packages' do
result = run_bolt_task('apt', 'action' => 'autoremove')
pin: { 'priority' => 200, 'release' => 'stretch-backports' })
}
end
+
context 'with defaults on ubuntu' do
let(:facts) do
{
pin: { 'priority' => 200, 'release' => 'bionac-backports' })
}
end
+
context 'with everything set' do
let(:facts) do
{
pin: { 'priority' => 90, 'release' => 'vivid' })
}
end
+
context 'when set things with hashes' do
let(:facts) do
{
}
end
end
+
describe 'mint tests' do
let(:facts) do
{
pin: { 'priority' => 200, 'release' => 'trusty-backports' })
}
end
+
context 'with missing location' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
end
end
+
context 'with missing release' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
end
end
+
context 'with missing repos' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
end
end
+
context 'with missing key' do
let(:params) do
{
end
end
end
+
describe 'validation' do
let(:facts) do
{
is_expected.to raise_error(Puppet::Error, %r{expects a})
end
end
+
context 'with invalid release' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{expects a})
end
end
+
context 'with invalid repos' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{expects a})
end
end
+
context 'with invalid key' do
let(:params) do
{
is_expected.to raise_error(Puppet::Error, %r{expects a})
end
end
+
context 'with invalid pin' do
let(:params) do
{
%r{Acquire::https::proxy "https://localhost:8080/";},
)
}
+
it {
is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
%r{Acquire::http::proxy "http://localhost:8080/";},
}
end
end
+
context 'with lots of non-defaults' do
let :params do
{
id: 'Debian',
},
},
- 'apt_update_last_success': factval,
+ apt_update_last_success: factval,
}
end
let(:pre_condition) do
is_expected.to contain_exec('apt_update').with('refreshonly' => false)
end
end
+
context 'and Exec[apt_update] refreshonly is overridden to true and has recent run' do
let(:facts) do
{
id: 'Debian',
},
},
- 'apt_update_last_success': Time.now.to_i,
+ apt_update_last_success: Time.now.to_i,
}
end
let(:pre_condition) do
end
end
end
+
context "when apt::update['frequency']='reluctantly'" do
{
'a recent run' => Time.now.to_i,
id: 'Debian',
},
},
- 'apt_update_last_success': factval,
+ apt_update_last_success: factval,
}
end
let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
end
end
end
+
['daily', 'weekly'].each do |update_frequency|
context "when apt::update['frequency'] has the value of #{update_frequency}" do
{ 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
id: 'Debian',
},
},
- 'apt_update_last_success': factval,
+ apt_update_last_success: factval,
}
end
let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
id: 'Debian',
},
},
- 'apt_update_last_success': Time.now.to_i,
+ apt_update_last_success: Time.now.to_i,
}
end
let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
is_expected.to contain_exec('apt_update').with('refreshonly' => true)
end
end
+
context 'when $apt_update_last_success is nil' do
let(:facts) do
{
id: 'Debian',
},
},
- 'apt_update_last_success': nil,
+ apt_update_last_success: nil,
}
end
let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
server: 'keyserver.ubuntu.com',
content: nil)
}
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
server: 'keyserver.ubuntu.com',
content: nil)
end
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present")
end
server: 'keyserver.ubuntu.com',
content: nil)
end
+
it 'contains the apt_key absent anchor' do
is_expected.to contain_anchor("apt_key #{title} absent")
end
it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with(contains_apt_key_example(title))
end
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
server: 'hkp://pgp.mit.edu')
end
end
+
context 'with url and port number' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'when url character limit is exceeded' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with incorrect port number url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with incorrect protocol for url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with missing port number url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with url ending with a dot' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with url begin with a dash' do
let(:params) do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with invalid key' do
let :title do
'Out of rum. Why? Why are we out of rum?'
it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with(default_apt_key_example(title))
end
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with(title_key_example)
end
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present")
end
it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with(absent_apt_key(title))
end
+
it 'contains the apt_key absent anchor' do
is_expected.to contain_anchor("apt_key #{title} absent")
end
it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with(bunch_things_apt_key_example(title, params))
end
+
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
server: 'hkp://pgp.mit.edu')
end
end
+
context 'when url with port number' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'when character url exceeded' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with incorrect port number url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with incorrect protocol for url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with missing port number url' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with url ending with a dot' do
let :params do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'when url begins with a dash' do
let(:params) do
{
is_expected.to raise_error(%r{expects a match})
end
end
+
context 'with invalid key' do
let :title do
'Out of rum. Why? Why are we out of rum?'
is_expected.to contain_apt__key('duplicate').with(id: title,
ensure: 'present')
end
+
it 'contains two apt::key resource - title' do
is_expected.to contain_apt__key(title).with(id: title,
ensure: 'present')
it 'contains only a single apt_key - duplicate' do
is_expected.to contain_apt_key('duplicate').with(default_apt_key_example(title))
end
+
it 'contains only a single apt_key - no title' do
is_expected.not_to contain_apt_key(title)
end
end
it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n}) }
+
it {
is_expected.to contain_apt__setting('pref-my_pin').with('priority' => 99)
}
let(:title) { 'ppa:needs/substitution' }
it { is_expected.not_to contain_package('python-software-properties') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
.that_notifies('Class[Apt::Update]')
let(:title) { 'ppa:needs/substitution' }
it { is_expected.to contain_package('software-properties-common') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
.that_notifies('Class[Apt::Update]')
let(:title) { 'ppa:needs/substitution' }
it { is_expected.not_to contain_package('python-software-properties') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
.that_notifies('Class[Apt::Update]')
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('software-properties-common') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
.that_notifies('Class[Apt::Update]')
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
.that_notifies('Class[Apt::Update]')
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
.that_notifies('Class[Apt::Update]')
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
+
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
.that_notifies('Class[Apt::Update]')
is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
end
end
+
context 'with location' do
let(:params) { { location: 'hello.there' } }
it {
is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
}
+
it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
end
it {
is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n})
}
+
it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) }
end
before(:each) do
allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
end
+
it { is_expected.to be_nil }
end
allow(File).to receive(:executable?) # Stub all other calls
allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false)
end
+
it { is_expected.to be_nil }
end
"Conf planet.rb (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to be true }
end
end
before(:each) do
allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
before(:each) do
allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
"Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to eq(['extremetuxracer', 'planet.rb']) }
end
end
before(:each) do
allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has security updates' do
before(:each) do
allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
"Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to eq(2) }
end
end
before(:each) do
allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
end
+
it { is_expected.to be_nil }
end
allow(File).to receive(:executable?) # Stub all other calls
allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false)
end
+
it { is_expected.to be_nil }
end
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to be true }
end
end
before(:each) do
allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
before(:each) do
allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to eq(['tzdata', 'unhide.rb']) }
end
end
allow(File).to receive(:file?).and_return(true)
allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true)
end
+
it { is_expected.to eq true }
end
allow(File).to receive(:file?).and_return(true)
allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false)
end
+
it { is_expected.to eq false }
end
end
before(:each) do
allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has security updates' do
before(:each) do
allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
- it { is_expected.to be nil }
+
+ it { is_expected.to be_nil }
end
describe 'when apt has updates' do
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
end
+
it { is_expected.to eq(2) }
end
end
['adv', '--no-tty', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'],
).and_return('uid:-::::1284991450::07BEBE04F4AE4A8E885A761325717D8509D9C1DC::Ubuntu Extras Archive Automatic Signing Key <ftpmaster@ubuntu.com>::::::::::0:')
end
+
it 'returns no resources' do
expect(described_class.instances.size).to eq(0)
end
['adv', '--no-tty', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'],
).and_return(command_output)
end
+
it 'returns 2 resources' do # rubocop:disable RSpec/MultipleExpectations
expect(described_class.instances.size).to eq(2)
expect(described_class.instances[0].name).to eq('630239CC130E1A7FD81A27B140976EAF437D05B5')