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

Cannot override module Hiera 5 config for unit tests #487

Closed
ragnarkon opened this issue Apr 25, 2018 · 4 comments
Closed

Cannot override module Hiera 5 config for unit tests #487

ragnarkon opened this issue Apr 25, 2018 · 4 comments

Comments

@ragnarkon
Copy link

ragnarkon commented Apr 25, 2018

There appears to be no way to override the module layer Hiera 5 configuration in for unit tests. Having the ability to override the Hiera 5 module layer configuration would extremely helpful, particularly when running unit tests on eyaml data where the developer (or CI pipeline) may not have access to the public/private keys.

Furthermore, if the developer did have access to the public/private keys, the hiera-eyaml gem is not included in the Gemfile by default, causing unit tests to fail. (Admittedly, an easy problem for the user to fix themselves.)

Current Behavior

failed: rspec: ./spec/classes/init_spec.rb:9: error during compilation: Evaluation Error:
Error while evaluating a Function Call, Function Load Error for function
'eyaml_lookup_key': Lookup using eyaml lookup_key function is only supported when
the hiera_eyaml library is present (line: 3, column: 1)

Example ./hiera5.yaml that should be overwritten:

version: 5
defaults:
  datadir: data
  lookup_key: eyaml_lookup_key
  options:
    pkcs7_private_key: /etc/puppetlabs/code/keys/private_key.pkcs7.pem
    pkcs7_public_key: /etc/puppetlabs/code/keys/public_key.pkcs7.pem
hierarchy:

  - name: "Common Eyaml"
    path: "common.eyaml"

./spec/fixtures/hiera/hiera.yaml file used for unit tests:

version: 5
defaults:
  datadir: spec/fixtures/hiera/data
  data_hash: yaml_data
hierarchy:

  - name: "Common Eyaml"
    path: "common.eyaml"

./spec/spec_helper.rb:

# ...
default_fixtures_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))

RSpec.configure do |c|
  c.default_facts = default_facts
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!
  end
  # Hiera config file for unit tests
  c.hiera_config = File.join(default_fixtures_path, 'hiera/hiera.yaml')
end
@ragnarkon
Copy link
Author

A similar issue appears to have been reported here: rodjek/rspec-puppet#626

@ardrigh
Copy link
Contributor

ardrigh commented Apr 26, 2018

This should be considered alongside the addition of Hiera support in general, similar to ticket open #424

I have also been trying to unit test with rspec and hiera config files and having mixed success.

It would also be helpful to have a standard directory structure where these testing Hiera files could exist, since it's up to the user to decide currently.

@nabertrand
Copy link
Contributor

@ragnarkon @ardrigh see rodjek/rspec-puppet#626 (comment) for a possible workaround. If that works for you it's easy enough to add to your .sync.yml spec_overrides so it doesn't get clobbered on your next pdk update

@scotje scotje added the needs-triage Newly created issue that has not been reviewed by a PDK contributor label May 15, 2019
@scotje
Copy link
Contributor

scotje commented May 16, 2019

Closing this in favor of the linked rspec-puppet ticket. Once it has been resolved there it will be included in the subsequent PDK release.

@scotje scotje closed this as completed May 16, 2019
@scotje scotje removed the needs-triage Newly created issue that has not been reviewed by a PDK contributor label May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants