unit testing and eyaml

154 views
Skip to first unread message

Stanislav Khromoy

unread,
Feb 24, 2017, 12:16:43 PM2/24/17
to Puppet Users

Need a little help with integrating unit testing ( rspec-puppet ) with eyaml encrypted data in hiera.

I have something like this in heira:

foo::foo_api_key: ENC[super long string of stuff]

manifest:

 class { '::some_module_from_forge':
   apikey => hiera('foo::foo_api_key')
 }

foo_spec.rb

it { should contain_class('stackdriver').with_apikey(ENC[super long string of stuff])}

I am not really sure how to quote this properly. Everything I've tried comes back with an error

Tom Poulton

unread,
Feb 24, 2017, 3:54:20 PM2/24/17
to Puppet Users
Hi

Look into rspec-puppet-utils, you can use the MockFunction class to completely mock hiera (there's an example in the readme). This way your tests never even execute the real hiera function, so you don't need to worry about yaml files, eyaml files, hierarchies, eyaml installation, eyaml keys, etc

This is more like unit testing in a Java/C#/ruby project, where you're isolating what you want to test away from it's dependencies. Mocking hiera allows your tests to be very flexible with minimal setup, and you're also not testing hiera/hiera-ayaml functionality in your tests for foo

Full disclosure: I wrote rspec-puppet-utils so naturally I think it's a useful tool and a good fit in this case, but there are other ways of doing it :)

Does that make sense? I hope it helps
Reply all
Reply to author
Forward
0 new messages