Reputation: 47
I am trying to write rspec test the puppet code. In my puppet, I called a define type which is not part of this class. (previously defined) The puppet code works find in branch test, but rspec could not pass the "reuire". Puppet:
$gluster_path = '/usr/libexec/zabbix-gluster'
$gluster_discovery_script = "${gluster_path}/gstatus_discovery.py"
$user_param_lines = [
"UserParameter=gluster_volume_info[*],${gluster_discovery_script} \$1 \$2\n",
"UserParameter=gluster_storage_info[*],${gluster_discovery_script} \$1\n",
"UserParameter=gluster_volume_name.discovery,${gluster_discovery_script}\n",
]
...
zabbix::agent::userparam { 'glusterfs':
content => join($user_param_lines, ''),
}
Rspec:
...
it {
is_expected.to contain_zabbix__agent__userparam('cnvr-zabbix-gluster')
}
define type:
define zabbix::agent::userparam($content = undef, $source = undef) {
...
file { "/etc/zabbix/zabbix_agentd.d/userparameter_${title}.conf":
...
require => [
Package['zabbix-agent'],
File['zabbix_agentd_dir'],
],
content => $content,
source => $_source,
notify => Service['zabbix-agent'],
}
The zabbix-agent has been installed from other modules. But error keeps prompting:
Puppet::Error: Could not find resource 'Package[zabbix-agent]' in parameter 'require' (file: /home/edwu/puppet/modules/zabbix/manifests/agent/userparam.pp, line: 17) on node
Is there a way I can skip this requirement checking in rspec?
Upvotes: 0
Views: 491
Reputation: 180093
Is there a way I can skip this requirement checking in rspec?
The error reported in the RSpec test is a catalog compilation error. It is in no way specific to RSpec. Indeed, it is pointing to a bona fide weakness in zabbix::agent::userparam
, and a resulting probable flaw in your class under test. This is precisely one of the reasons for writing RSpec tests!
The issue is that zabbix::agent::userparam
does not stand independently. It requires Package['zabbix-agent']
to be declared, but it neither declares it itself nor declares a class that does. Your class under test inherits this weakness, though the farther you get from the the center of the issue, the more you have to lean toward calling it a bug, as opposed to simply a weakness. Your class, too, could declare the needed other class, and it probably should do.
You cannot cause the catalog builder to let a requirement on a non-existent resource pass unremarked, nor should you want to do, because this is among the kinds of things that you want your tests to reveal to you. But if you want to allow this weakness in your class to persist, then you can use an RSpec pre-condition to make RSpec declare the appropriate class for you, so that the requirement is actually satisfied.
Upvotes: 0