Skip to content

Commit

Permalink
Improve custom fact handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Nov 19, 2017
1 parent b2b8640 commit e167b51
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
14 changes: 0 additions & 14 deletions moduleroot/spec/default_facts.yml.erb

This file was deleted.

1 change: 1 addition & 0 deletions moduleroot/spec/facts/puppetlabs/concat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_custom_fact :concat_basedir, '/tmp'
18 changes: 18 additions & 0 deletions moduleroot/spec/facts/puppetlabs/stdlib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments'
add_custom_fact :puppet_vardir, '/opt/puppetlabs/puppet/cache'
add_custom_fact :root_home, '/root'
add_custom_fact :service_provider, ->(os, facts) do
case facts[:osfamily]
when 'RedHat'
facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'sysv'
when 'Debian'
if (facts[:operatingsystem] == 'Debian' && facts[:operatingsystemmajrelease].to_i >= 8) ||
(facts[:operatingsystem] == 'Ubuntu' && facts[:operatingsystemmajrelease].to_i >= 16)
'systemd'
else
'sysv'
end
else
'sysv'
end
end
1 change: 1 addition & 0 deletions moduleroot/spec/facts/voxpupuli/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_custom_fact :staging_http_get, 'curl'
30 changes: 23 additions & 7 deletions moduleroot/spec/spec_helper.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ puts 'augeasproviders: setting Puppet[:libdir] to work around broken type autolo
# libdir is only a single dir, so it can only workaround loading of one external module
Puppet[:libdir] = "#{Puppet[:modulepath]}/augeasproviders_core/lib"
<% end -%>
if Dir.exist?(File.expand_path('../../lib', __FILE__))
require 'coveralls'
Expand All @@ -32,14 +33,29 @@ if Dir.exist?(File.expand_path('../../lib', __FILE__))
end
end
## Custom fact handling
# Included in Facter, but excluded from rspec-puppet-facts
add_custom_fact :puppetversion, Puppet.version
add_custom_fact :facterversion, Facter.version
add_custom_fact :ipaddress, "172.16.254.254"
add_custom_fact :is_pe, false
add_custom_fact :macaddress, "AA:AA:AA:AA:AA:AA"
metadata = JSON.load File.read('metadata.json')
metadata["dependencies"].each do |dependency|
if dependency["name"]
filename = "facts/#{dependency["name"]}"
require_relative filename if File.exists?("spec/#{filename}.rb")
end
end
if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__))).each do |fact, value|
add_custom_fact fact.to_sym, value
end
end
RSpec.configure do |c|
default_facts = {
puppetversion: Puppet.version,
facterversion: Facter.version
}
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['mock_with'] -%>
c.mock_with <%= @configs['mock_with'] %>
<%- end -%>
Expand Down

0 comments on commit e167b51

Please sign in to comment.