Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to test my cookbook w/ ChefSpec when including datadog::dd-handler #338

Closed
jeffbyrnes opened this issue Aug 8, 2016 · 3 comments · Fixed by #396
Closed

Unable to test my cookbook w/ ChefSpec when including datadog::dd-handler #338

jeffbyrnes opened this issue Aug 8, 2016 · 3 comments · Fixed by #396
Labels
Milestone

Comments

@jeffbyrnes
Copy link
Contributor

jeffbyrnes commented Aug 8, 2016

I’m using datadog v2.5.0.

I have a cookbook, with a recipe that:

include_recipe 'datadog::dd-agent'
include_recipe 'datadog::dd-handler'

However, this is the output I get:

6) ds_base::monitoring When all attributes are default, on Ubuntu 16.04 converges successfully
   Failure/Error: expect { chef_run }.to_not raise_error

     expected no Exception, got #<LoadError: cannot load such file -- chef/handler/datadog> with backtrace:
       # /var/folders/30/nsmp68z977s8q1x10z4h9_fr0000gn/T/chefspec20160808-17741-60xwg5file_cache_path/cookbooks/datadog/recipes/dd-handler.rb:38:in `from_file'
       # /var/folders/30/nsmp68z977s8q1x10z4h9_fr0000gn/T/chefspec20160808-17741-60xwg5file_cache_path/cookbooks/ds_base/recipes/monitoring.rb:12:in `from_file'
       # ./spec/unit/recipes/monitoring_spec.rb:24:in `block (3 levels) in <top (required)>'
       # ./spec/unit/recipes/monitoring_spec.rb:28:in `block (4 levels) in <top (required)>'
       # ./spec/unit/recipes/monitoring_spec.rb:28:in `block (3 levels) in <top (required)>'
   # ./spec/unit/recipes/monitoring_spec.rb:28:in `block (3 levels) in <top (required)>'

If I chef gem install chef-handler-datadog, things work properly, but that feels a bit janky.

@olivielpeau
Copy link
Member

Hi @jeffbyrnes and thanks for your feedback!

The dd-handler recipe has to require chef/handler/datadog because some versions of the chef_handler cookbook need this require statement to work properly.

Obviously using the require doesn't work when the chef-handler-datadog gem hasn't actually been installed by the chef_gem resource that precedes the require. So dd-handler doesn't work for chefspec runs and for chef runs that use the why-run mode (see related issue #118).

The only thing I can think of to fix your issue properly on our end would be to remove this require and change the version constraint on the chef_handler dep to a version that can load the handler on its own. This would require quite some testing on the cookbook to determine which version of chef_handler works well, I'll try to spend some time on this for the next minor release.

In the short term I don't think there's a way to fix this other than what you did (i.e. installing the gem locally). Let me know what you think, thanks!

See also https://github.com/chef-cookbooks/chef_handler/issues/21

@olivielpeau olivielpeau added this to the Triage milestone Aug 9, 2016
@jeffbyrnes
Copy link
Contributor Author

@olivielpeau very helpful, thanks!

@martinisoft
Copy link
Contributor

A trick we've done ourselves is to use ChefSpec to stub out the recipe call to avoid it entirely. Here is a snippet:

before(:each) do
    allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original
    allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('datadog::dd-handler').and_return('true')
end

This will allow other recipes through but stub out the dd-handler recipe entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants