apt_has_updates_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'spec_helper'
  2. describe 'apt_has_updates fact' do
  3. subject { Facter.fact(:apt_has_updates).value }
  4. after(:each) { Facter.clear }
  5. describe 'on non-Debian distro' do
  6. before {
  7. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat'
  8. }
  9. it { should be_nil }
  10. end
  11. describe 'on Debian based distro missing update-notifier-common' do
  12. before {
  13. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  14. File.stubs(:executable?) # Stub all other calls
  15. File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false
  16. }
  17. it { should be_nil }
  18. end
  19. describe 'on Debian based distro with broken packages' do
  20. before {
  21. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  22. File.stubs(:executable?) # Stub all other calls
  23. Facter::Util::Resolution.stubs(:exec) # Catch all other calls
  24. File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
  25. Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Error: BrokenCount > 0"
  26. }
  27. it { should be_nil }
  28. end
  29. describe 'on Debian based distro with unknown error with semicolons' do
  30. before {
  31. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  32. File.stubs(:executable?) # Stub all other calls
  33. Facter::Util::Resolution.stubs(:exec) # Catch all other calls
  34. File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
  35. Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Unknown Error: 'This error contains something that could be parsed like 4;3' (10)"
  36. }
  37. it { should be_nil }
  38. end
  39. describe 'on Debian based distro' do
  40. before {
  41. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  42. File.stubs(:executable?) # Stub all other calls
  43. Facter::Util::Resolution.stubs(:exec) # Catch all other calls
  44. File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
  45. Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "4;3"
  46. }
  47. it { should be true }
  48. end
  49. end