Skip to content

Commit

Permalink
Refactor default fact loading
Browse files Browse the repository at this point in the history
This gets rids of the default facts because our modules do not rely on
them.

More importantly it switches to using add_custom_fact so we don't break
the built in facts from rspec-puppet-facts.
  • Loading branch information
ekohl committed Dec 25, 2018
1 parent f56a3e8 commit 66d1e3c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 2 additions & 0 deletions config_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Rakefile:
default_enabled_rake_targets:
- 'metadata_lint'
- 'release_checks'
spec/default_facts.yml:
delete: true
spec/classes/coverage_spec.rb:
delete: true
spec/acceptance/nodesets/centos-511-x64.yml:
Expand Down
13 changes: 0 additions & 13 deletions moduleroot/spec/default_facts.yml.erb

This file was deleted.

15 changes: 10 additions & 5 deletions moduleroot/spec/spec_helper.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

if File.exist?(File.join(__dir__, 'default_module_facts.yml'))
facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml')))
if facts
facts.each do |name, value|
add_custom_fact name.to_sym, value
end
end
end

<% if @configs['augeasproviders'] -%>
# Setup augeasproviders
require 'pathname'
Expand Down Expand Up @@ -42,14 +51,10 @@ if Dir.exist?(File.expand_path('../../lib', __FILE__))
end

RSpec.configure do |c|
default_facts = {}
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
<%- if @configs['hiera_config'] -%>
c.hiera_config = <%= @configs['hiera_config'] %>
<%- end -%>

<%- end -%>
# Coverage generation
c.after(:suite) do
RSpec::Puppet::Coverage.report!
Expand Down

0 comments on commit 66d1e3c

Please sign in to comment.