1fc5ab6b120540ff92b3c32a6125f4f3d12579c3
[puppet-modules/puppetlabs-apt.git] / spec / unit / facter / apt_has_updates_spec.rb
1 # frozen_string_literal: true
2
3 require 'spec_helper'
4
5 describe 'apt_has_updates fact' do
6   subject { Facter.fact(:apt_has_updates).value }
7
8   before(:each) { Facter.clear }
9
10   describe 'on non-Debian distro' do
11     before(:each) do
12       allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
13     end
14     it { is_expected.to be_nil }
15   end
16
17   describe 'on Debian based distro missing apt-get' do
18     before(:each) 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)
22     end
23     it { is_expected.to be_nil }
24   end
25
26   describe 'on Debian based distro' do
27     before(:each) do
28       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
29       allow(File).to receive(:executable?) # Stub all other calls
30       allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
31       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
32       apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
33                    "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
34                    "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \
35                    "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
36       allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
37     end
38     it { is_expected.to be true }
39   end
40 end