A couple more questions came up today as I continued writing and testing.
Most of the examples I’ve been able to find of HWRP don’t make very
extensive use of already existing chef core resources. I guess LWRPs are
more generally used for this?
Basically the provider I’m writing is assembling mostly basic chef
resources, but in a complex enough way that I have a number of helper
methods, and wanted to break things up into more modular method calls to do
the work and make testing easier.
I found early on that providers include the recipe dsl, so I can use
primitives like “template,” “cookbook_file,” etc. as opposed to
Chef::Resource::Template. This also had the positive side effect of (with
just a little work), letting me use chefspec to both ensure that things
don’t fully converge on my test box and get access to its nice rspec
Then I got to thinking that the recipe dsl is adding things to the
resource_collection, even if i manually call run_action on the resource
during my provider action. So it is added to the resource collection after
my HWRP, and touched again even though it doesn’t re-run the action (still
can’t figure out where that is getting skipped, but glad it is).
Is this use of the recipe dsl in providers a dark path I shouldn’t be
treading down? Like I said, I really haven’t found many full providers out
there that make heavy use of core chef resources and even fewer that have
On Sun, Jan 26, 2014 at 10:04 AM, Joshua Timberman email@example.com:
When I rewrote the runit_service definition to be a service resource,
I made it “heavyweight” for two reasons:
I wanted to subclass Chef’s service resource, to reuse some of its
functionality and have runit_service behave like other services.
It was easier to do unit testing of it this way. You can see the
unit tests here:
For testing LWRPs, you can use the step_into feature of ChefSpec.
Documentation is on the ChefSpec site.
Hope this helps.
On Thu, Jan 23, 2014 at 4:59 PM, Benjamin Bytheway firstname.lastname@example.org
I have a cookbook that uses LWRPs to configure some weblogic domains.
LWRP is getting really complex and deserves (I think) to be made into an
HWRP with more complete unit tests, etc.
Does anyone know of best practices for unit testing HRWPs like this?
I found that the dsh cookbook (https://github.com/rcbops-cookbooks/dsh)
have a spec tested HWRP, which ends up stubbing method calls on the chef
providers used to prevent them from converging on the test machine. Is
the best approach to take?
Anyone have suggestions or places to start digging?
Joshua Timberman, Chef.