Showing with 48 additions and 1 deletion.
  1. +8 −0 CHANGELOG.md
  2. +10 −0 lib/facter/grafana_version.rb
  3. +1 −1 metadata.json
  4. +29 −0 spec/facter/grafana_version_spec.rb
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v14.1.0](https://github.com/voxpupuli/puppet-grafana/tree/v14.1.0) (2024-06-20)

[Full Changelog](https://github.com/voxpupuli/puppet-grafana/compare/v14.0.0...v14.1.0)

**Implemented enhancements:**

- Add fact to get grafana version [\#367](https://github.com/voxpupuli/puppet-grafana/pull/367) ([rwaffen](https://github.com/rwaffen))

## [v14.0.0](https://github.com/voxpupuli/puppet-grafana/tree/v14.0.0) (2024-06-14)

[Full Changelog](https://github.com/voxpupuli/puppet-grafana/compare/v13.2.0...v14.0.0)
Expand Down
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
version_path = '/usr/share/grafana/VERSION'
confine { File.exist?(version_path) }

setcode do
File.read(version_path).strip
end
end
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-grafana",
"version": "14.0.0",
"version": "14.1.0",
"author": "Vox Pupuli",
"summary": "This module provides Grafana, a dashboard and graph editor for Graphite and InfluxDB.",
"license": "Apache-2.0",
Expand Down
29 changes: 29 additions & 0 deletions spec/facter/grafana_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'facter'

describe 'grafana_version' do
before do
Facter.clear
end

context 'when VERSION file exists' do
it 'returns the version from the VERSION file' do
version = '1.2.3'
version_path = '/usr/share/grafana/VERSION'

allow(File).to receive(:exist?).with(version_path).and_return(true)
allow(File).to receive(:read).with(version_path).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