/
support.rb
38 lines (30 loc) · 886 Bytes
/
support.rb
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
32
33
34
35
36
37
38
module RSpec::Puppet
module Support
@@cache = {}
protected
def build_catalog_without_cache(nodename, facts_val, code)
Puppet[:code] = code
node_obj = Puppet::Node.new(nodename)
node_obj.merge(facts_val)
# trying to be compatible with 2.7 as well as 2.6
if Puppet::Resource::Catalog.respond_to? :find
Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
else
Puppet::Resource::Catalog.indirection.find(node_obj.name, :use_node => node_obj)
end
end
public
def build_catalog *args
@@cache[args] ||= self.build_catalog_without_cache(*args)
end
def munge_facts(facts)
output = {}
facts.keys.each { |key| output[key.to_s] = facts[key] }
output
end
def escape_special_chars(string)
string.gsub!(/\$/, "\\$")
string
end
end
end