Skip to content

Commit

Permalink
Merge pull request #160 from bastelfreak/fact
Browse files Browse the repository at this point in the history
Add version fact
  • Loading branch information
bastelfreak authored Jul 10, 2022
2 parents 2e85164 + 44343c6 commit a811dba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Examples](#examples)
* [Restore Script](#restore-script)
* [Prometheus Exporter](#prometheus-exporter)
* [Facts](#facts)
* [Limitations](#limitations)
* [Tests](#tests)
* [Contributions](#contributions)
Expand Down Expand Up @@ -102,6 +103,21 @@ More and more people use prometheus. We vendor a bash script that can provide
you metrics about your backups in the prometheus format. They are written to
disk and the node\_exporter can collect them.

## Facts

This module provides you a structed fact, named `borgbackup`. It currently only
lists the borgbackup version. It's a structured so it can easily be extended
without breaking changes and without further topscope pollution.

```
# puppet facts show borgbackup
{
"borgbackup": {
"version": "1.2.1"
}
}
```

## Limitations

On CentOS 8, the PowerTools repository needs to be enabled by the user.
Expand Down
11 changes: 11 additions & 0 deletions lib/facter/borgbackup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

Facter.add(:borgbackup) do
confine do
Facter::Util::Resolution.which('borg')
end
setcode do
version = Facter::Util::Resolution.exec('borg --version').split.last
{ 'version' => version }
end
end
30 changes: 30 additions & 0 deletions spec/unit/facter/borgbackup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'spec_helper'
command_output = 'borg 1.1.16'
fact_output = { 'version' => '1.1.16' }
describe Facter::Util::Fact.to_s do
before { Facter.clear }

context 'borg not in path' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('borg').and_return(nil)
end

it { expect(Facter.fact(:borgbackup).value).to eq(nil) }
end

context 'valid run' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('borg').and_return('/usr/bin/borg')
end

context 'borgbackup version' do
before do
allow(Facter::Util::Resolution).to receive(:exec).with('borg --version') { command_output }
end

it { expect(Facter.fact(:borgbackup).value).to eq fact_output }
end
end
end

0 comments on commit a811dba

Please sign in to comment.