Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock facter version based on puppet version & unit tests: print puppet/facter version #1355

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_geo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::geo' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe 'nginx::resource::location' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_mailhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::mailhost' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::map' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::server' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_snippet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::snippet' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::streamhost' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/resource_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx::resource::upstream' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
end

RSpec.configure do |c|
# getting the correct facter version is tricky. We use facterdb as a source to mock facts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to submit this to modulesync as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. I just need to test it here.

# see https://github.com/camptocamp/facterdb
# people might provide a specific facter version. In that case we use it.
# Otherwise we need to match the correct facter version to the used puppet version.
# as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14
# https://puppet.com/docs/puppet/5.5/about_agent.html
c.default_facter_version = if ENV['FACTERDB_FACTS_VERSION']
ENV['FACTERDB_FACTS_VERSION']
else
Gem::Dependency.new('', ENV['PUPPET_VERSION']).match?('', '5') ? '3.11.0' : '3.14.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, 3.11 and 3.14 (without the .0) would work now. But that's not important.

end

# Coverage generation
c.after(:suite) do
RSpec::Puppet::Coverage.report!
Expand Down