Skip to content

Commit

Permalink
Use server binary to get version
Browse files Browse the repository at this point in the history
The `mongosh` command we want to use as client has different versioning
compared to the server, this used to be the same versioning when the old
client was used.
  • Loading branch information
stevenpost committed Mar 25, 2024
1 parent b6d3f5f commit e7ecd03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/facter/mongodb_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Facter.add(:mongodb_version) do
setcode do
if Facter::Core::Execution.which('mongo')
mongodb_version = Facter::Core::Execution.execute('mongo --version 2>&1')
%r{MongoDB shell version:?\s+v?([\w.]+)}.match(mongodb_version)[1]
if Facter::Core::Execution.which('mongod')
mongodb_version = Facter::Core::Execution.execute('mongod --version 2>&1')
%r{^db version:?\s+v?([\w.]+)}.match(mongodb_version)[1]
end
end
end
6 changes: 3 additions & 3 deletions spec/unit/mongodb_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
describe 'mongodb_version' do
context 'with value' do
before do
allow(Facter::Core::Execution).to receive(:which).with('mongo').and_return(true)
allow(Facter::Core::Execution).to receive(:execute).with('mongo --version 2>&1').and_return('MongoDB shell version: 3.2.1')
allow(Facter::Core::Execution).to receive(:which).with('mongod').and_return(true)
allow(Facter::Core::Execution).to receive(:execute).with('mongod --version 2>&1').and_return('db version v5.0.6')
end

it {
expect(Facter.fact(:mongodb_version).value).to eq('3.2.1')
expect(Facter.fact(:mongodb_version).value).to eq('5.0.6')
}
end
end
Expand Down

0 comments on commit e7ecd03

Please sign in to comment.