Skip to content

Commit 657ea10

Browse files
authored
Merge pull request #548 from rodjek/issue-547
Don't clobber the existing networking facts hash
2 parents 90ffc5d + 54f95df commit 657ea10

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/rspec-puppet/support.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ def facts_hash(node)
214214
'fqdn' => node,
215215
'domain' => node.split('.', 2).last,
216216
'clientcert' => node,
217-
'networking' => {
218-
'fqdn' => node,
219-
'domain' => node.split('.', 2).last,
220-
'hostname' => node.split('.').first
221-
}
217+
}
218+
219+
networking_facts = {
220+
'hostname' => node_facts['hostname'],
221+
'fqdn' => node_facts['fqdn'],
222+
'domain' => node_facts['domain'],
222223
}
223224

224225
result_facts = if RSpec.configuration.default_facts.any?
@@ -231,6 +232,8 @@ def facts_hash(node)
231232
result_facts.merge!(munge_facts(facts)) if self.respond_to?(:facts)
232233
result_facts.merge!(munge_facts(node_facts))
233234

235+
(result_facts['networking'] ||= {}).merge!(networking_facts)
236+
234237
# Facter currently supports lower case facts. Bug FACT-777 has been submitted to support case sensitive
235238
# facts.
236239
downcase_facts = Hash[result_facts.map { |k, v| [k.downcase, v] }]

spec/classes/test_basic_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
let(:node) { 'test123.test.com' }
99
let(:facts) do
1010
{
11-
:fqdn => 'notthis.test.com',
11+
:fqdn => 'notthis.test.com',
12+
:networking => {
13+
:primary => 'eth0',
14+
},
1215
}
1316
end
1417

1518
it { should contain_notify('test123.test.com') }
1619
it { should_not contain_notify('notthis.test.com') }
20+
21+
context 'existing networking facts should not be clobbered', :if => Puppet.version.to_f >= 4.0 do
22+
let(:pre_condition) { 'notify { [$facts["networking"]["primary"], $facts["networking"]["hostname"]]: }' }
23+
24+
it { should contain_notify('eth0') }
25+
it { should contain_notify('test123') }
26+
end
1727
end
1828
end

0 commit comments

Comments
 (0)