summaryrefslogtreecommitdiff
path: root/spec/unit/facter/systemd_version_spec.rb
blob: 5007dc69c873b98bf89b93285d83fc215184b63d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require "spec_helper"

describe Facter::Util::Fact do
  before {
    Facter.clear
  }

  describe "systemd_version" do
    context 'returns version when systemd fact present' do
      before do
        Facter.fact(:systemd).stubs(:value).returns(true)
      end
      let(:facts) { {:systemd => true} }
      it do
        Facter::Util::Resolution.expects(:exec).with("systemctl --version | awk '/systemd/{ print $2 }'").returns('229')
        expect(Facter.value(:systemd_version)).to eq('229')
      end
    end
    context 'returns nil when systemd fact not present' do
      before do
        Facter.fact(:systemd).stubs(:value).returns(false)
      end
      let(:facts) { {:systemd => false } }
      it do
        Facter::Util::Resolution.stubs(:exec)
        Facter::Util::Resolution.expects(:exec).with("systemctl --version | awk '/systemd/{ print $2 }'").never
        expect(Facter.value(:systemd_version)).to eq(nil)
      end
    end
  end
end