forked from bfraser/puppet-grafana
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from rwaffen/add_version_fact
Add fact to get grafana version
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |