Hi list,

I've written a custom puppet function that I'd like to test using *rspec*. 
It's source code is available here :: 
https://github.com/riton/rspec-hiera-test-function/blob/master/lib/puppet/parser/functions/test_hiera.rb#L10
.

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()'.

I want to use hiera as described in 
https://github.com/rodjek/rspec-puppet/tree/v2.0.0#hiera-integration.
This mean:

   - I want to provide a hierarchy
   - I want hiera to use my custom configuration file as described in 
   https://github.com/rodjek/rspec-puppet/tree/v2.0.0#enabling-hiera-lookups

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.
I just want that the hiera() lookup actually uses my custom hierarchy 
specified in my configuration file (
https://github.com/riton/rspec-hiera-test-function/blob/master/spec/fixtures/hiera/hiera.yaml
)

As described in my sample repository README (
https://github.com/riton/rspec-hiera-test-function/blob/master/README.md), 
right now I wasn't able to make it work.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/59a73336-4f64-4c35-9a74-7288dc773dcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to