267e2bfae68e344024ac6c5ff4c363853aa797a1
[puppet-modules/puppetlabs-apt.git] / spec / unit / facter / apt_package_updates_spec.rb
1 # frozen_string_literal: true
2
3 require 'spec_helper'
4
5 describe 'apt_package_updates fact' do
6   subject { Facter.fact(:apt_package_updates).value }
7
8   before(:each) { Facter.clear }
9
10   describe 'when apt has no updates' do
11     before(:each) do
12       allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false)
13     end
14     it { is_expected.to be nil }
15   end
16
17   describe 'when apt has updates' do
18     before(:each) do
19       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
20       allow(File).to receive(:executable?) # Stub all other calls
21       allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
22       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
23       apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
24                    "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
25                    "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
26                    "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
27       allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
28     end
29     it { is_expected.to eq(['tzdata', 'unhide.rb']) }
30   end
31 end