Skip to content

Commit

Permalink
add mdadmversion fact
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Nov 8, 2013
1 parent 4675af2 commit 172ae55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/facter/mdadmversion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add('mdadmversion') do
mdadm = Facter.value(:mdadm)
setcode do
unless mdadm.nil?
# `mdadm --version` sends it's output to stderr
Facter::Util::Resolution.exec("#{mdadm} --version 2>&1")
end
end
end
21 changes: 21 additions & 0 deletions spec/unit/facts/mdadmversion_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe 'mdadmversion', :type => :fact do
before(:each) { Facter.clear }

context 'mdadm fact => /sbin/madam' do
it 'should get the version string' do
Facter.fact(:mdadm).stubs(:value).returns('/sbin/mdadm')
Facter::Util::Resolution.stubs(:exec).with('/sbin/mdadm --version 2>&1').returns('mdadm - v3.2.3 - 23rd December 2011')

Facter.fact(:mdadmversion).value.should == 'mdadm - v3.2.3 - 23rd December 2011'
end
end

context 'mdadm fact not set' do
it 'should return nil' do
Facter.fact(:mdadm).stubs(:value).returns(nil)
Facter.fact(:mdadmversion).value.should be_nil
end
end
end

0 comments on commit 172ae55

Please sign in to comment.