From 3947719df36970d4c2f5b3c83bf104811be20025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20R=C3=A9p=C3=A1si?= Date: Tue, 18 Jul 2023 14:39:25 +0200 Subject: [PATCH] spec test --- spec/unit/facter/volume_group_map_spec.rb | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 spec/unit/facter/volume_group_map_spec.rb diff --git a/spec/unit/facter/volume_group_map_spec.rb b/spec/unit/facter/volume_group_map_spec.rb new file mode 100644 index 00000000..a59001c3 --- /dev/null +++ b/spec/unit/facter/volume_group_map_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'volume_group_map fact' do + before :each do + Facter.clear + end + + context 'when not on Linux' do + it 'is set to nil' do + Facter.fact(:kernel).expects(:value).at_least(1).returns('SunOs') + expect(Facter.value(:volume_group_map)).to be_nil + end + end + + context 'when on Linux' do + before :each do + Facter.fact(:kernel).expects(:value).at_least(1).returns('Linux') + end + + context 'when vgs is absent' do + before :each do + Facter::Core::Execution.stubs('exec') # All other calls + Facter::Core::Execution.expects('which').with('vgs').at_least(1).returns(nil) + end + + it 'is set to nil' do + expect(Facter.value(:volume_group_map)).to be_nil + end + end + + context 'when vgs is present' do + before :each do + Facter::Core::Execution.stubs('exec') # All other calls + Facter::Core::Execution.expects('which').with('vgs').at_least(1).returns('/sbin/vgs') + end + + it 'is able to resolve vgs and map pvs' do + Facter.fact(:volume_groups).expects(:value).returns( + { + 'centos' => { + 'uuid' => 'ZcFkEG-217a-nnc6-PvWx-oXou-7THt-XR6eci', + 'attr' => 'wz--n-', 'permissions' => 'writeable', + 'allocation_policy' => 'normal', + 'size' => '19.51g', + 'free' => '44.00m' + }, + 'tasks' => { + 'uuid' => 'tMqdQC-ukEx-bEft-bLk8-WoM1-jX0a-0p1rri', + 'attr' => 'wz--n-', + 'permissions' => 'writeable', + 'allocation_policy' => 'normal', + 'size' => '3.99g', + 'free' => '2.82g' + } + }, + ) + vgs_centos_output = <<-OUTPUT + /dev/sda + OUTPUT + vgs_centos_output.dup.lstrip! + Facter::Core::Execution.expects(:exec).at_least(1).with('vgs -o pv_name centos --noheading --nosuffix').returns(vgs_centos_output) + vgs_tasks_output = <<-OUTPUT + /dev/sdc + /dev/sdd2 + OUTPUT + vgs_tasks_output.dup.lstrip! + Facter::Core::Execution.expects(:exec).at_least(1).with('vgs -o pv_name tasks --noheading --nosuffix').returns(vgs_tasks_output) + + expect(Facter.value(:volume_group_map)).to include( + 'centos' => '/dev/sda', + 'tasks' => '/dev/sdc,/dev/sdd2', + ) + end + end + end +end