1 # frozen_string_literal: true
5 describe 'apt_has_dist_updates fact' do
6 subject { Facter.fact(:apt_has_dist_updates).value }
8 before(:each) { Facter.clear }
10 describe 'on non-Debian distro' do
12 allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
14 it { is_expected.to be_nil }
17 describe 'on Debian based distro missing apt-get' do
19 allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
20 allow(File).to receive(:executable?) # Stub all other calls
21 allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false)
23 it { is_expected.to be_nil }
26 describe 'on Debian based distro' do
28 allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
29 allow(File).to receive(:executable?) # Stub all other calls
30 allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
31 allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
32 allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
33 apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
34 "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
35 "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n" \
36 "Conf planet.rb (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n"
37 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)
39 it { is_expected.to be true }