Skip to content

Commit f48fc81

Browse files
committed
Merge pull request voxpupuli#262 from jyaworski/add_mongodb_version_fact
Add mongodb_version fact
2 parents 95e89aa + 223366b commit f48fc81

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/facter/mongodb_version.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Facter.add(:mongodb_version) do
2+
setcode do
3+
if Facter::Core::Execution.which('mongo')
4+
mongodb_version = Facter::Core::Execution.execute('mongo --version 2>&1')
5+
%r{^MongoDB shell version: ([\w\.]+)}.match(mongodb_version)[1]
6+
end
7+
end
8+
end

spec/unit/mongodb_version_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
describe "mongodb_version" do
9+
context 'with value' do
10+
before :each do
11+
Facter::Core::Execution.stubs(:which).with('mongo').returns(true)
12+
Facter::Core::Execution.stubs(:execute).with('mongo --version 2>&1').returns('MongoDB shell version: 3.2.1')
13+
end
14+
it {
15+
expect(Facter.fact(:mongodb_version).value).to eq('3.2.1')
16+
}
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)