voxpupuli / onceover

Your gateway drug to automated infrastructure testing with Puppet
Apache License 2.0
142 stars 45 forks source link

Onceover::Controlrepo.facts.each do processing too many files #103

Closed sandymcp closed 6 years ago

sandymcp commented 7 years ago

Following the instructions for Onceover::Controlrepo.facts.each do |facts| context "on #{facts['fqdn']}" do let(:facts) { facts } it { should compile } end end BTW shouldn't it be Onceover::Controlrepo.new.facts.each as per the roles example?

In addition to my specified factsets, this also iterates over the default fact sets, is there a way to stop this without modifying the code? If I print out fact_files in the ControlRepo.Initialize I get /home/en10029/control-repo/spec/factsets/RHEL-7-3.json /home/en10029/control-repo/spec/factsets/Windows_Server-2012r2-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/solaris-11.2-sparc-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/AIX-6.1-powerpc.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/AIX-7.1-powerpc.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/CentOS-5.11-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Ubuntu-12.04-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Ubuntu-12.04-32.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/CentOS-6.6-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Debian-7.8-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Ubuntu-14.04-32.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Ubuntu-14.04-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Debian-7.8-32.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Windows_Server-2008r2-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/solaris-10_u9-sparc-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/SLES-11.3-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/CentOS-7.0-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Debian-6.0.10-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/CentOS-5.11-32.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/SLES-12.1-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/CentOS-6.6-32.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Windows_Server-2012r2-64.json /home/en10029/.gem/ruby/2.1.0/gems/onceover-3.2.0/factsets/Debian-6.0.10-32.json Looking at the code it's clear why.

@facts_files = opts[:facts_files] || [Dir["#{@facts_dir}/*.json"],Dir["#{File.expand_path('../../../factsets',__FILE__)}/*.json"]].flatten Reads both locations, but IMHO should read one or the other.

dylanratcliffe commented 6 years ago

This is an intended feature as people should be able to add their own factsets while also retaining use of the existing ones if they wish. If you wanted more functionality around which factsets are used when I'd recommend using the Onceover::TestConfig object like so:

repo = Onceover::Controlrepo.new
config = Onceover::TestConfig.new(repo.onceover_yaml)

config.spec_tests.each do |test|
  # Do something here
end

This is just written from the top of my head so it might not work but that will mean you can use the actual onceover.yaml file to determine what facts get run against what classes etc.