sethvargo/chefspec — pull request #306 by kampfschlaefer (2014-01-08 11:13:33+00:00)
Title: Restart work towards a working minimal example of chef-search

This is neither minimal nor is it working. I can't seem to figure out how to mock a node with working fqdn (that is not fauxhai.local). I did figure out a way to mock the nodes with actually running a cookbook, but the fqdn is still wrong or not existant.

My use case it rather simple (at least I think it is):

> I have a recipe "foo" that searches for nodes with an attribute "bar" set or with the recipe "bar" applied. Then foo logs the names and fqdns of the found hosts.

Something like that is working in the munin cookbook (there its writing fqdns and ipaddresses to the munin server config). And probably also in the nagios cookbook and many others.

I want to prove (by chefspec testing) that the above works. So I want to mock out an environment (not yet an actual chef-environment) that has three nodes, ham (fqdn: ham.example.com) and bacon (fqdn:bacon.example.com) that have the bar-recipe applied and the bar-attribute set and one node tomato (fqdn: tomato.example.com) without the bar-recipe or bar-attribute.
Then chefspec should converge its "local" node with the foo-recipe and test that the names and fqdns of the wanted nodes ham and bacon are logged. And test that neither name nor fqdn of tomato is logged.

But I can't figure out how to mock out nodes with fqdn (or hostname and domain) set to anything else the fauxhai.local. And I tried several ways in this example.

On a sidenote: I am getting kind of frustrated that it now takes me the fourth (or fifth) day already to figure that out. Why oes it seem as if there is no complete documentation for this use case? Is this just such a marginal use case that no one gives it any thought? Am I wrong with wanting to test this use case? Should I just give up on chefspec and look at minitest-handler and run our recipes on real nodes in our dev-environment?