Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

(FACT-2615) Add Solaris mountpoints fact #515

Merged
merged 1 commit into from
May 14, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/facts/solaris/mountpoints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Facts
module Solaris
class Mountpoints
FACT_NAME = 'mountpoints'

def call_the_resolver
mountpoints = Facter::Resolvers::Linux::Mountpoints.resolve(FACT_NAME.to_sym)
return Facter::ResolvedFact.new(FACT_NAME, nil) unless mountpoints

fact = {}
mountpoints.each do |mnt|
fact[mnt[:path].to_sym] = mnt.reject { |k| k == :path }
end

Facter::ResolvedFact.new(FACT_NAME, fact)
end
end
end
end
60 changes: 60 additions & 0 deletions spec/facter/facts/solaris/mountpoints_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

describe Facts::Solaris::Mountpoints do
describe '#call_the_resolver' do
subject(:fact) { Facts::Solaris::Mountpoints.new }

context 'when resolver returns hash' do
let(:resolver_output) do
[{ available: '63.31 GiB',
available_bytes: 67_979_685_888,
capacity: '84.64%',
device: '/dev/nvme0n1p2',
filesystem: 'ext4',
options: %w[rw noatime],
path: '/',
size: '434.42 GiB',
size_bytes: 466_449_743_872,
used: '348.97 GiB',
used_bytes: 374_704_357_376 }]
end
let(:parsed_fact) do
{ '/' => { 'available' => '63.31 GiB',
'available_bytes' => 67_979_685_888,
'capacity' => '84.64%',
'device' => '/dev/nvme0n1p2',
'filesystem' => 'ext4',
'options' => %w[rw noatime],
'size' => '434.42 GiB',
'size_bytes' => 466_449_743_872,
'used' => '348.97 GiB',
'used_bytes' => 374_704_357_376 } }
end

before do
allow(Facter::Resolvers::Linux::Mountpoints).to receive(:resolve).with(:mountpoints).and_return(resolver_output)
end

it 'calls Facter::Resolvers::Linux::Mountpoints' do
fact.call_the_resolver
expect(Facter::Resolvers::Linux::Mountpoints).to have_received(:resolve).with(:mountpoints)
end

it 'returns mountpoints information' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'mountpoints', value: parsed_fact)
end
end

context 'when resolver returns nil' do
before do
allow(Facter::Resolvers::Linux::Mountpoints).to receive(:resolve).with(:mountpoints).and_return(nil)
end

it 'returns mountpoints information' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'mountpoints', value: nil)
end
end
end
end