From 6e51be76ea09c83d5d1615ad2de50428829559f7 Mon Sep 17 00:00:00 2001 From: Dustin Lactin Date: Wed, 29 Apr 2015 11:36:51 -0600 Subject: [PATCH] Added new apt_reboot_required fact, updated readme, and added unit tests --- README.md | 4 +++- lib/facter/apt_reboot_required.rb | 7 ++++++ spec/unit/facter/apt_reboot_required_spec.rb | 23 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/facter/apt_reboot_required.rb create mode 100644 spec/unit/facter/apt_reboot_required_spec.rb diff --git a/README.md b/README.md index e8e6d39..3ec5f43 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,8 @@ apt::sources: * `apt_update_last_success`: The date, in epochtime, of the most recent successful `apt-get update` run (based on the mtime of /var/lib/apt/periodic/update-success-stamp). +* `apt_reboot_required`: Determines if a reboot is necessary after updates have been installed. + #### Class: `apt` Main class, includes all other classes. @@ -443,4 +445,4 @@ Puppet Labs modules on the Puppet Forge are open projects, and community contrib For more information, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html) -To see who's already involved, see the [list of contributors.](https://github.com/puppetlabs/puppetlabs-apt/graphs/contributors) \ No newline at end of file +To see who's already involved, see the [list of contributors.](https://github.com/puppetlabs/puppetlabs-apt/graphs/contributors) diff --git a/lib/facter/apt_reboot_required.rb b/lib/facter/apt_reboot_required.rb new file mode 100644 index 0000000..8de904a --- /dev/null +++ b/lib/facter/apt_reboot_required.rb @@ -0,0 +1,7 @@ +# apt_reboot_required.rb +Facter.add(:apt_reboot_required) do + confine :osfamily => 'Debian' + setcode do + File.file?('/var/run/reboot-required') + end +end diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb new file mode 100644 index 0000000..ab3490a --- /dev/null +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'apt_reboot_required fact' do + subject { Facter.fact(:apt_reboot_required).value } + after(:each) { Facter.clear } + + describe 'if a reboot is required' do + before { + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:file?).returns true + } + it { expect(Facter.fact(:apt_reboot_required).value).to eq true } + end + + describe 'if a reboot is not required' do + before { + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:file?).returns false + } + it { expect(Facter.fact(:apt_reboot_required).value).to eq false } + end + +end -- 2.45.2