rodjek / rspec-puppet

RSpec tests for your Puppet manifests
http://rspec-puppet.com
MIT License
362 stars 202 forks source link

The server_facts_hash method should allow overrides #659

Open trevor-vaughan opened 6 years ago

trevor-vaughan commented 6 years ago

There are various times when you need to be able to test against different server versions, particularly with the changes in puppet 5.4.1+.

Users should be able to use let(:server_facts) to set their own hash attributes similarly to let(:facts)

jcbollinger commented 6 years ago

It's not just to test against different Puppet versions that one might want to override entries in the $server_facts hash. It came up in the comments thread of #643 that one might want to override the servername, and although one vocal commenter seemed not to appreciate the importance, such an override is indeed necessary for testing some important scenarios.

One should first recognize that in the real world, the $servername can indeed plausibly differ from $server_facts[servername], because the client can provide the former as a fact, whereas the server provides the latter. Perhaps, then, the client is configured to use one of the server's aliases to contact it, whereas server_facts gives the server's idea of its own name. Alternatively, the client might try to inject falsified data. One would like to be able to test such scenarios to ensure that classes sensitive to them behave in the desired way, but that does not seem presently to be possible.

trevor-vaughan commented 6 years ago

I, for one, configure Puppet with Puppet because, you know, automation and things: https://github.com/simp/pupmod-simp-pupmod/blob/master/spec/classes/master_spec.rb#L19