Search code examples
puppetrspec-puppet

Rspec + puppet: nested fixtures?


i am trying to start using rspec to test some already made (and in production) puppet modules, but this thing keep trying to make me mad.

First off, i am doing a "complete" test with rake. The task is:

Rakefile:

desc 'Validate manifests, templates, and ruby files'
task :validate do
  Dir['manifests/**/*.pp'].each do |manifest|
    sh "puppet parser validate --noop #{manifest}"
  end
  Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
    sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
  end
  Dir['templates/**/*.erb'].each do |template|
    sh "erb -P -x -T '-' #{template} | ruby -c"
  end
end

desc 'Run metadata_lint, lint, validate, and spec tests.'
task :test do
  [:metadata_lint, :lint, :validate, :spec].each do |test|
    Rake::Task[test].invoke
  end

The first issue i had was with this error:

  1) rcphp should contain Package[rcphp]
     Failure/Error: it { is_expected.to contain_package('rcphp') }

     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Resource Statement, Could not find declared class rcphp at line 1:1 on node test.example.com

After researching a while, i found out that i should put the modules i was using in the .fixtures.yml. Sounded simple enought, so i made:

fixtures:
  symlinks:
    rcphp: "#{source_dir}"
  repositories:
    php: "git://github.com/voxpupuli/puppet-php.git"
    inifile: "git://github.com/puppetlabs/puppetlabs-inifile.git"
  forge_modules:
    stdlib:
      repo: "puppetlabs/stdlib"
      ref: "4.12.0"

From this point forward, things quit making any sense. I got the error:

 Failure/Error: contain "::yum::repo::${yum_repo}"

 Puppet::PreformattedError:
   Evaluation Error: Error while evaluating a Function Call, Could not find class ::yum::repo::remi_php56 for test.example.com at /home/luis.brandao/git/rcphp/spec/fixtures/modules/php/manifests/repo/redhat.pp:12:3 on node test.example.com

The ::yum::repo was called by the PHP module. The php module have its own fixtures. I tried adding that, and another nested module dependency poped up. This cant be right, i am supposed to figure it out and add, by hand, ALL the dependency tree to make a simple test??


Solution

  • This cant be right, i am supposed to figure it out and add, by hand, ALL the dependency tree to make a simple test??

    Yes, that's correct at the moment.