-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unbound_version: add spec tests to the unbound_version fact
- Loading branch information
Showing
3 changed files
with
59 additions
and
13 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 |
---|---|---|
@@ -1,18 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
unbound_bin = case Facter.value('kernel') | ||
when 'FreeBSD' | ||
'/usr/local/sbin/unbound' | ||
else | ||
'/usr/sbin/unbound' | ||
end | ||
if File.exist? unbound_bin | ||
unbound_version = Facter::Util::Resolution.exec( | ||
"#{unbound_bin} -V 2>&1" | ||
).match(%r{Version\s+(\d+(?:\.\d+)*)})[1] | ||
Facter.add(:unbound_version) do | ||
setcode do | ||
unbound_version | ||
Facter.add(:unbound_version) do | ||
confine { Facter.value(:kernel) != 'windows' } | ||
setcode do | ||
if Facter::Util::Resolution.which('unbound') | ||
unbound_version = Facter::Util::Resolution.exec('unbound -V 2>&1') | ||
%r{Version\s+(\d+(?:\.\d+){2})\s+}.match(unbound_version)[1] | ||
end | ||
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
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,52 @@ | ||
require 'spec_helper' | ||
|
||
version_string = <<-VERSION | ||
unbound: invalid option -- 'V' | ||
usage: unbound [options] | ||
start unbound daemon DNS resolver. | ||
-h this help | ||
-c file config file to read instead of /etc/unbound/unbound.conf | ||
file format is described in unbound.conf(5). | ||
-d do not fork into the background. | ||
-v verbose (more times to increase verbosity) | ||
Version %s | ||
linked libs: libevent 2.0.21-stable (it uses epoll), OpenSSL 1.1.0l 10 Sep 2019 | ||
linked modules: dns64 python validator iterator | ||
BSD licensed, see LICENSE in source package for details. | ||
Report bugs to unbound-bugs@nlnetlabs.nl | ||
VERSION | ||
|
||
tests = { | ||
'valid' => ['1.1.1', '1.90.24', '1.0.404', '2.5.6'], | ||
'invalid' => ['1', '1.1', '1.1.1.1', '1,1,1', '2:5.1', 'foobar'] | ||
} | ||
describe Facter::Util::Fact.to_s do | ||
before { Facter.clear } | ||
context 'unbound not in path' do | ||
before do | ||
allow(Facter::Util::Resolution).to receive(:which).with('unbound') { false } | ||
end | ||
it { expect(Facter.fact(:unbound_version).value).to eq(nil) } | ||
end | ||
tests.each_pair do |test, versions| | ||
describe "test #{test} versions" do | ||
before do | ||
allow(Facter::Util::Resolution).to receive(:which).with('unbound') { true } | ||
end | ||
versions.each do |version| | ||
context "test version #{version}" do | ||
before do | ||
allow(Facter::Util::Resolution).to receive(:exec).with('unbound -V 2>&1') do | ||
version_string % version | ||
end | ||
end | ||
if test == 'valid' | ||
it { expect(Facter.fact(:unbound_version).value).to eq(version) } | ||
else | ||
it { expect(Facter.fact(:unbound_version).value).to eq(nil) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |