Hi list,
I've written a custom puppet function that I'd like to test using rspec.
This function (is useless, I know :-)) only does a hiera lookup of variable name 'variable'.
Thus, the following two puppet codes:
# code 1
$value = hiera('variable')
# code 2
$value = test_hiera()
should be equivalent.
So far, no problem.
Then comes rspec testing of my function 'test_hiera()'.
This mean:
I've already been using the method above for testing puppet code that involves hiera lookups, and it worked as expected.
What I don't want is to stub or mock hiera function.
It seems that hiera is still using it's default configuration file.
A strace of the following command:
$ strace bundle exec rake spec SPEC_OPTS='--color --format documentation --tag focus'
reveals that /var/lib/hiera/common.yaml is searched for.
My test environment is:
- CentOS 6
- ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
- Bundler version 1.7.12
My bundle is:
- bundler (1.7.12)
- diff-lcs (1.2.5)
- facter (1.7.6)
- hiera (1.3.4)
- json_pure (1.8.2)
- metaclass (0.0.4)
- mocha (1.1.0)
- puppet (3.6.2)
- puppet-lint (1.1.0)
- puppet-syntax (1.4.1)
- puppetlabs_spec_helper (0.8.2)
- rake (10.4.2)
- rgen (0.6.6)
- rspec (2.99.0)
- rspec-core (2.99.2)
- rspec-expectations (2.99.2)
- rspec-mocks (2.99.3)
- rspec-puppet (2.0.0 8459e14)
If anyone has already succeeded testing custom functions that internally uses hiera lookup, I'll be glad to learn how.
I've tested everything I can for now and I'm quite out of ideas.
Thanks in advance
Rémi