|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'volume_group_map fact' do |
| 6 | + before :each do |
| 7 | + Facter.clear |
| 8 | + end |
| 9 | + |
| 10 | + context 'when not on Linux' do |
| 11 | + it 'is set to nil' do |
| 12 | + Facter.fact(:kernel).expects(:value).at_least(1).returns('SunOs') |
| 13 | + expect(Facter.value(:volume_group_map)).to be_nil |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + context 'when on Linux' do |
| 18 | + before :each do |
| 19 | + Facter.fact(:kernel).expects(:value).at_least(1).returns('Linux') |
| 20 | + end |
| 21 | + |
| 22 | + context 'when vgs is absent' do |
| 23 | + before :each do |
| 24 | + Facter::Core::Execution.stubs('exec') # All other calls |
| 25 | + Facter::Core::Execution.expects('which').with('vgs').at_least(1).returns(nil) |
| 26 | + end |
| 27 | + |
| 28 | + it 'is set to nil' do |
| 29 | + expect(Facter.value(:volume_group_map)).to be_nil |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'when vgs is present' do |
| 34 | + before :each do |
| 35 | + Facter::Core::Execution.stubs('exec') # All other calls |
| 36 | + Facter::Core::Execution.expects('which').with('vgs').at_least(1).returns('/sbin/vgs') |
| 37 | + end |
| 38 | + |
| 39 | + it 'is able to resolve vgs and map pvs' do |
| 40 | + Facter.fact(:volume_groups).expects(:value).returns( |
| 41 | + { |
| 42 | + 'centos' => { |
| 43 | + 'uuid' => 'ZcFkEG-217a-nnc6-PvWx-oXou-7THt-XR6eci', |
| 44 | + 'attr' => 'wz--n-', 'permissions' => 'writeable', |
| 45 | + 'allocation_policy' => 'normal', |
| 46 | + 'size' => '19.51g', |
| 47 | + 'free' => '44.00m' |
| 48 | + }, |
| 49 | + 'tasks' => { |
| 50 | + 'uuid' => 'tMqdQC-ukEx-bEft-bLk8-WoM1-jX0a-0p1rri', |
| 51 | + 'attr' => 'wz--n-', |
| 52 | + 'permissions' => 'writeable', |
| 53 | + 'allocation_policy' => 'normal', |
| 54 | + 'size' => '3.99g', |
| 55 | + 'free' => '2.82g' |
| 56 | + } |
| 57 | + }, |
| 58 | + ) |
| 59 | + vgs_centos_output = <<-OUTPUT |
| 60 | + /dev/sda |
| 61 | + OUTPUT |
| 62 | + vgs_centos_output.dup.lstrip! |
| 63 | + Facter::Core::Execution.expects(:exec).at_least(1).with('vgs -o pv_name centos --noheading --nosuffix').returns(vgs_centos_output) |
| 64 | + vgs_tasks_output = <<-OUTPUT |
| 65 | + /dev/sdc |
| 66 | + /dev/sdd2 |
| 67 | + OUTPUT |
| 68 | + vgs_tasks_output.dup.lstrip! |
| 69 | + Facter::Core::Execution.expects(:exec).at_least(1).with('vgs -o pv_name tasks --noheading --nosuffix').returns(vgs_tasks_output) |
| 70 | + |
| 71 | + expect(Facter.value(:volume_group_map)).to include( |
| 72 | + 'centos' => '/dev/sda', |
| 73 | + 'tasks' => '/dev/sdc,/dev/sdd2', |
| 74 | + ) |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments