Class: PuppetUnitTests::FakeFacter

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_unit_tests/fake_facter.rb

Overview

Pretend to be Facter just for tests.

Instance Method Summary collapse

Constructor Details

#initializeFakeFacter

Returns a new instance of FakeFacter.



6
7
8
# File 'lib/puppet_unit_tests/fake_facter.rb', line 6

def initialize
  @facts = {}
end

Instance Method Details

#add(name, _opts = {}, &block) ⇒ Object



24
25
26
27
28
# File 'lib/puppet_unit_tests/fake_facter.rb', line 24

def add(name, _opts = {}, &block)
  raise "Facter.add expects a block" unless block

  @facts[name.to_s] = block.call
end

#clearObject



16
17
18
# File 'lib/puppet_unit_tests/fake_facter.rb', line 16

def clear
  @facts.clear
end

#debugging(arg) ⇒ Object



30
# File 'lib/puppet_unit_tests/fake_facter.rb', line 30

def debugging(arg); end

#resetObject



32
# File 'lib/puppet_unit_tests/fake_facter.rb', line 32

def reset; end

#search(*paths) ⇒ Object



34
# File 'lib/puppet_unit_tests/fake_facter.rb', line 34

def search(*paths); end

#setup_loggingObject



36
# File 'lib/puppet_unit_tests/fake_facter.rb', line 36

def setup_logging; end

#to_hashObject



20
21
22
# File 'lib/puppet_unit_tests/fake_facter.rb', line 20

def to_hash
  @facts
end

#value(fact_name) ⇒ Object



10
11
12
13
14
# File 'lib/puppet_unit_tests/fake_facter.rb', line 10

def value(fact_name)
  @facts.dig(*fact_name.to_s.split("."))
rescue TypeError
  nil
end