Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fact to get grafana version #367

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/facter/grafana_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

Facter.add(:grafana_version) do
confine { Facter::Util::Resolution.which('grafana-server') }
rwaffen marked this conversation as resolved.
Show resolved Hide resolved

setcode do
version_path = '/usr/share/grafana/VERSION'
File.read(version_path).strip if File.exist?(version_path)
end
end
28 changes: 28 additions & 0 deletions spec/facter/grafana_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'facter'

describe 'grafana_version' do
before do
Facter.clear
allow(Facter::Util::Resolution).to receive(:which).with('grafana-server').and_return('/usr/sbin/grafana-server')
end

context 'when VERSION file exists' do
it 'returns the version from the VERSION file' do
version = '1.2.3'
allow(File).to receive(:exist?).with('/usr/share/grafana/VERSION').and_return(true)
allow(File).to receive(:read).with('/usr/share/grafana/VERSION').and_return(version)

expect(Facter.fact(:grafana_version).value).to eq(version.strip)
end
end

context 'when VERSION file does not exist' do
it 'returns nil' do
allow(File).to receive(:exist?).with('/usr/share/grafana/VERSION').and_return(false)

expect(Facter.fact(:grafana_version).value).to be_nil
end
end
end
Loading