ChefSpec and unit-testing recipes with artifact-cookbook callbacks.
Closed this issue · 4 comments
Hi,
I have some limitations when testing my recipes with the artifact LWRP using ChefSpec...
In fact, i just test the parameters passed to the action. for example :
expect(chef_run_i1_jar).to deploy_artifact("xx-client")
.with(version: "1.14.1-SNAPSHOT",
artifact_location: "xxx:xx-client:jar",
deploy_to: "D:/java/clt/xx-client")
But i'd also like to test all others LWRP that should be executed in the "callback functions" (i.e. before_extract, after_deploy, etc.). The thing is : the Procs designed by these functions are not run during ChefSpec executions (and most of the code I'd like to test is inside these functions..).
What options do I have ?
- Include the execution of LWRP by adding
step_into: ["artifact_deploy"]
to the ChefSpec::Runner constructor. Problem is that, there's no way to include a LWRP as a cookbook dependency (it's just not found and I get a RecipeNotFound : issue explained here : customink-webops/hostsfile#4) - Find a way to include callback function in the "run_list" and compile them as regular recipes.
I don't like the first option anyway. A Unit Test should not execute LWRP but just "simulate" them.
I'd like to find a solution close to the second option..but not sure if it's technically possible.
What's your point of view ?
How do you unit-test your recipes with artifact-cookbook when they have most of their workflow in callback functions ?
Thanks.
@florentdupont nice writeup here. Unfortunately, I'm not sure I have a satisfactory answer. In many cases, we aren't unit testing our recipes.
I think the idea makes sense though, and I can offer a few ideas. I think they might all extend outward from one grander idea - a rewrite of this LWRP to implement Chef::Provider::LWRPBase
.
From there, you'd get...
- a better ability to unit test this actual LWRP
- the possibility of some adding testability to the procs.
Thank you for you answer. That'd be great but this might take a lot of work to refactor the existing LWRP to implement LWRPBase. For now, I think we are just going to unit-test by testing the parameters passed to the action.
To make some further tests, we'll use some integration tests (like Test-Kitchen).
I'd also like to unit test my recipes. Has this changed since August?