---
+.gitlab-ci.yml:
+ unmanaged: true
+
+.rubocop.yml:
+ default_configs:
+ inherit_from: .rubocop_todo.yml
+ require:
+ - rubocop-i18n
+ - rubocop-rspec
+
.travis.yml:
docker_sets:
- set: docker/debian-8
branches:
- release
+appveyor.yml:
+ delete: true
+
Gemfile:
required:
':system_tests':
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
- gem: puppet-lint-i18n
-.rubocop.yml:
- default_configs:
- inherit_from: .rubocop_todo.yml
- require:
- - rubocop-i18n
- - rubocop-rspec
-
Rakefile:
requires:
- puppet_pot_generator/rake_tasks
-appveyor.yml:
- delete: true
-
-.gitlab-ci.yml:
- unmanaged: true
+spec/spec_helper.rb:
+ mock_with: ':rspec'
+ coverage_report: true
"template-url": "https://github.com/puppetlabs/pdk-templates/",
"template-ref": "1.9.0-0-g7281db5",
"pdk-version": "1.9.0"
-}
\ No newline at end of file
+}
+RSpec.configure do |c|
+ c.mock_with :rspec
+end
+
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
end
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
c.after(:suite) do
+ RSpec::Puppet::Coverage.report!(0)
end
end
describe 'on non-Debian distro' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat'
+ allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
end
it { is_expected.to be_nil }
end
describe 'on Debian based distro missing apt-get' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns false
+ allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
+ 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
describe 'on Debian based distro' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test'
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_dist_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test'
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
end
describe 'on Debian' do
"Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \
end
- if Facter.version < '2.0.0'
- it { is_expected.to eq('vim') }
- else
- it { is_expected.to eq(['vim']) }
- end
+ it { is_expected.to eq(['vim']) }
end
describe 'on Ubuntu' do
"Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n"
end
- if Facter.version < '2.0.0'
- it { is_expected.to eq('extremetuxracer,vim') }
- else
- it { is_expected.to eq(['extremetuxracer', 'vim']) }
- end
+ it { is_expected.to eq(['extremetuxracer', 'vim']) }
end
end
end
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_dist_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test'
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_dist_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has security updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test'
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
end
describe 'on Debian' do
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_dist_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test'
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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
describe 'on non-Debian distro' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat'
+ allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
end
it { is_expected.to be_nil }
end
describe 'on Debian based distro missing apt-get' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns false
+ allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
+ 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
describe 'on Debian based distro' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
end
describe 'on Debian' do
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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
describe 'if a reboot is required' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:file?).returns true
- File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ 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
describe 'if a reboot is not required' do
before(:each) do
- Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
- File.stubs(:file?).returns true
- File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns false
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ 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
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has security updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
+ allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
end
describe 'on Debian' do
describe 'on Debian based distro which has not yet created the update-success-stamp file' do
it 'has a value of -1' do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.expects(:exist?).with('/var/lib/apt/periodic/update-success-stamp').returns false
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:exist?).with('/var/lib/apt/periodic/update-success-stamp').and_return(false)
is_expected.to eq(-1)
end
end
describe 'on Debian based distro which has created the update-success-stamp' do
it 'has the value of the mtime of the file' do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:exist?).returns true
- File.stubs(:mtime).returns 1_407_660_561
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:exist?).and_return(true)
+ allow(File).to receive(:mtime).and_return(1_407_660_561)
is_expected.to eq(1_407_660_561)
end
end
describe 'when apt has no updates' do
before(:each) do
- Facter.fact(:apt_has_updates).stubs(:value).returns false
+ allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
end
it { is_expected.to be nil }
end
describe 'when apt has updates' do
before(:each) do
- Facter.fact(:osfamily).stubs(:value).returns 'Debian'
- File.stubs(:executable?) # Stub all other calls
- Facter::Util::Resolution.stubs(:exec) # Catch all other calls
- File.expects(:executable?).with('/usr/bin/apt-get').returns true
+ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
+ allow(File).to receive(:executable?) # Stub all other calls
+ allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+ allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
"Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
"Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
- puts apt_output
- Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output
+ allow(Facter::Util::Resolution).to receive(:exec).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