diff --git a/Gemfile b/Gemfile index 902e049..c65a5be 100644 --- a/Gemfile +++ b/Gemfile @@ -1,76 +1,82 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' def location_for(place_or_version, fake_version = nil) git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} file_url_regex = %r{\Afile:\/\/(?.*)} if place_or_version && (git_url = place_or_version.match(git_url_regex)) [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else [place_or_version, { require: false }] end end ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') group :development do gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') gem "puppet-lint-i18n", require: false gem 'ed25519', '>= 1.2', '< 2.0' gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0' end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] +# puppet_version = ENV['PUPPET_GEM_VERSION'] +# facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] gems = {} -gems['puppet'] = location_for(puppet_version) +# gems['puppet'] = location_for(puppet_version) # If facter or hiera versions have been specified via the environment # variables -gems['facter'] = location_for(facter_version) if facter_version +# gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} # If we're using a Puppet gem on Windows which handles its own win32-xxx gem # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). gems['win32-dir'] = ['<= 0.4.9', require: false] gems['win32-eventlog'] = ['<= 0.6.5', require: false] gems['win32-process'] = ['<= 0.7.5', require: false] gems['win32-security'] = ['<= 0.2.5', require: false] gems['win32-service'] = ['0.8.8', require: false] end gems.each do |gem_name, gem_params| gem gem_name, *gem_params end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__FILE__}.local", File.join(Dir.home, '.gemfile'), ] +gem 'facter', path:"/Users/bogdan.irimie/projects/facter" +gem 'puppet', path:"/Users/bogdan.irimie/projects/puppet" +# gem 'facter' +gem 'pry-byebug' + + extra_gemfiles.each do |gemfile| if File.file?(gemfile) && File.readable?(gemfile) eval(File.read(gemfile), binding) end end # vim: syntax=ruby diff --git a/spec/unit/facter/apt_dist_has_updates_spec.rb b/spec/unit/facter/apt_dist_has_updates_spec.rb index 216050d..6130f27 100644 --- a/spec/unit/facter/apt_dist_has_updates_spec.rb +++ b/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -1,39 +1,39 @@ require 'spec_helper' describe 'apt_has_dist_updates fact' do subject { Facter.fact(:apt_has_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'on non-Debian distro' do before(:each) do 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 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 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" 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 end diff --git a/spec/unit/facter/apt_dist_package_security_updates_spec.rb b/spec/unit/facter/apt_dist_package_security_updates_spec.rb index 6355b79..4033a28 100644 --- a/spec/unit/facter/apt_dist_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe 'apt_package_security_dist_updates fact' do subject { Facter.fact(:apt_package_security_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no 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 } end describe 'when apt has updates' do before(:each) do 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 let(:apt_get_upgrade_output) do "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" \ "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(['vim']) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(['extremetuxracer', 'vim']) } end end end diff --git a/spec/unit/facter/apt_dist_package_updates_spec.rb b/spec/unit/facter/apt_dist_package_updates_spec.rb index bbe212e..59e02b8 100644 --- a/spec/unit/facter/apt_dist_package_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' describe 'apt_package_dist_updates fact' do subject { Facter.fact(:apt_package_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no 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 } end describe 'when apt has updates' do before(:each) do 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" 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 end diff --git a/spec/unit/facter/apt_dist_security_updates_spec.rb b/spec/unit/facter/apt_dist_security_updates_spec.rb index 8035f16..895a36c 100644 --- a/spec/unit/facter/apt_dist_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe 'apt_security_updates fact' do subject { Facter.fact(:apt_security_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no 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 } end describe 'when apt has security updates' do before(:each) do 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 let(:apt_get_upgrade_output) do "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" \ "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(1) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(2) } end end end diff --git a/spec/unit/facter/apt_dist_updates_spec.rb b/spec/unit/facter/apt_dist_updates_spec.rb index f9942af..112dca8 100644 --- a/spec/unit/facter/apt_dist_updates_spec.rb +++ b/spec/unit/facter/apt_dist_updates_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' describe 'apt_updates fact' do subject { Facter.fact(:apt_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no 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 } end describe 'when apt has updates' do before(:each) do 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" 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 end diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index f7a1ca9..ea3e085 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -1,38 +1,38 @@ require 'spec_helper' describe 'apt_has_updates fact' do subject { Facter.fact(:apt_has_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'on non-Debian distro' do before(:each) do 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 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 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" 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 end diff --git a/spec/unit/facter/apt_package_security_updates_spec.rb b/spec/unit/facter/apt_package_security_updates_spec.rb index 53b91bc..958fd00 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -1,50 +1,50 @@ require 'spec_helper' describe 'apt_package_security_updates fact' do subject { Facter.fact(:apt_package_security_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do 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 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 let(:apt_get_upgrade_output) do "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" \ "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(['curl']) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(['tzdata', 'curl']) } end end end diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 4b3e749..4c81d0c 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -1,29 +1,29 @@ require 'spec_helper' describe 'apt_package_updates fact' do subject { Facter.fact(:apt_package_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do 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 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" 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 end diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index b15cb4c..22f5617 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' describe 'apt_reboot_required fact' do subject { Facter.fact(:apt_reboot_required).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'if a reboot is required' do before(:each) do 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 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 end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index cde0158..4e4b54d 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -1,50 +1,50 @@ require 'spec_helper' describe 'apt_security_updates fact' do subject { Facter.fact(:apt_security_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do 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 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 let(:apt_get_upgrade_output) do "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" \ "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(1) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(2) } end end end diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index dc0fc54..f4858dd 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -1,25 +1,24 @@ require 'spec_helper' describe 'apt_update_last_success fact' do subject { Facter.fact(:apt_update_last_success).value } before(:each) { Facter.clear } - after(:each) { Facter.clear } describe 'on Debian based distro which has not yet created the update-success-stamp file' do it 'has a value of -1' do 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 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 end diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index e9d4c0d..1f1c15b 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -1,29 +1,29 @@ require 'spec_helper' describe 'apt_updates fact' do subject { Facter.fact(:apt_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do 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 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" 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 end