Created
September 14, 2021 17:48
-
-
Save op-ct/c1eea1a85a9abef19c9bff208bdf477b to your computer and use it in GitHub Desktop.
Rake tasks to help set up onceover spec tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# These tasks help revionics use onceover to validate their manifests and data | |
# | |
# To prep and run onceover spec tests, run: | |
# | |
# bundler exec rake spec | |
# | |
namespace :onceover do | |
desc 'Install modules from Puppetfile, using private Puppet Forge' | |
task :puppetfile_install do | |
sh 'r10k -c spec/private-forge-r10k.yaml puppetfile install -v info' | |
end | |
desc "Prepare a spec/hiera.yaml that doesn't use eyaml backends" | |
task :spec_prep_hiera do | |
require 'yaml' | |
data = YAML.load_file('hiera.yaml') | |
data['defaults']['datadir'] = File.join('..', data['defaults']['datadir']) | |
data['hierarchy'].select { |x| (x['lookup_key'] || '') == 'eyaml_lookup_key' }.each do |x| | |
x.delete('lookup_key') | |
x.delete('options') | |
mocked_paths = x['paths'].map { |i| File.join('../spec/data/mocked_eyaml', i) } | |
x['paths'] = mocked_paths + x['paths'] | |
end | |
data['hierarchy'].unshift( | |
{ | |
'name'=> 'Mocked EYAML lookups (overrides ALL other hiera)', | |
'paths' => ['../spec/data/mocked_eyaml/override_everything.yaml'], | |
} | |
) | |
File.open('spec/hiera.yaml', 'w') do |f| | |
f.puts('# Generated by rake task onceover:spec_prep_hiera') | |
f.puts(data.to_yaml) | |
end | |
end | |
desc 'Run onceover spec tests and display Puppet errors' | |
task spec_prep: %i[puppetfile_install spec_prep_hiera] | |
desc 'Run onceover spec tests and display Puppet errors' | |
task spec_standalone: %i[spec_prep_hiera] do |_t, args| | |
ENV['SHOW_PUPPET_OUTPUT'] = 'true' | |
sh "onceover run spec -s #{args.to_a.join(',')}" | |
end | |
desc 'Run onceover spec tests and display Puppet errors' | |
task spec: %i[puppetfile_install spec_standalone] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment