rodjek / rspec-puppet

RSpec tests for your Puppet manifests
http://rspec-puppet.com
MIT License
364 stars 205 forks source link

Hiera function default arg is not parsed properly #351

Open rnelson0 opened 8 years ago

rnelson0 commented 8 years ago

I have the following code in a manifest:

$local_users = hiera('local_users', undef)

This generates an error like this:

     Failure/Error: it { is_expected.to create_sudo__conf('wheel') }
     Puppet::Error:
       Evaluation Error: Error while evaluating a Function Call, Could not find data item local_users in any Hiera data file and no default supplied at /home/rnelson0/puppet/controlrepo/dist/profile/spec/fixtures/modules/profile/manifests/base.pp:48:18 on node build02.nelson.va

However, puppet apply doesn't mind it at all. I believe rspec-puppet is not calling or mocking up hiera properly. Hiera lookups for values that do exist, do function as expected.

cbrinker commented 8 years ago

I'm seeing the same failure for the hiera_hash('key', {}) flavor

cbrinker commented 8 years ago

The underlying hiera-puppet-helper library has the problem. Made up a PR to resolve the behavior: https://github.com/mthibaut/hiera-puppet-helper/pull/6

rodjek commented 7 years ago

@rnelson0 are you seeing this when using hiera-puppet-helper or when using Puppet's hiera function?

rnelson0 commented 7 years ago

I'm not using hiera-puppet-helper, just puppetlabs_spec_helper and this in my spec/spec_helper.rb:

RSpec.configure do |c|
  c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml'))
end