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 version fact #160

Merged
merged 1 commit into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
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
@@ -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
@@ -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