Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I don't think you should test for that. The idea with rspec is that you test your module, so the logic within it and its structure, to see if it will behave as expected.

Where your data comes from is not part of how your module functions, hence it shouldn't be part of your module's tests. Your module should have parameters through which data is passed into your module. Wether that data then comes from Hiera or some other source is in essence irrelevant.

As an example:

class ntp($servers = hiera('ntp_servers') {
  ... do stuff ...
}

What you should be testing is wether that module manages to install the necessary packages and compiles a template that contains whatever was passed into $servers, not wether it manages to do a Hiera lookup for ntp_servers.

I might very well use your module like this:

class { 'ntp':
  servers => '192.168.1.1',
}

In that case, I'm not even doing a Hiera lookup but I'm still using that code. However, it would be useful to validate that whatever gets passed in through server actually is a valid IP or hostname and that the ntp.conf actually contains those values.

I don't think you should test for that. The idea with rspec is that you test your module, so the logic within it and its structure, to see if it will behave as expected.

Where your data comes from is not part of how your module functions, hence it shouldn't be part of your module's tests. Your module should have parameters through which data is passed into your module. Wether that data then comes from Hiera or some other source is in essence irrelevant.

As an example:

class ntp($servers = hiera('ntp_servers') {
  ... do stuff ...
}

What you should be testing is wether that module manages to install the necessary packages and compiles a template that contains whatever was passed into $servers, not wether it manages to do a Hiera lookup for ntp_servers.

I might very well use your module like this:

class { 'ntp':
  servers => '192.168.1.1',
}

In that case, I'm not even doing a Hiera lookup but I'm still using that code. However, it would be useful to validate that whatever gets passed in through server actually is a valid IP or hostname and that the ntp.conf actually contains those values.

When you're splitting up your code into modules, profiles and roles I can understand that you want to validate your hiera lookups at the profile level, in which case rspec-puppet-hiera is a good fit. But for actual module code, I think you shouldn't.