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

How to mock policy_group in ChefSpec? #971

Open
mrmarbury opened this issue Sep 16, 2019 · 1 comment
Open

How to mock policy_group in ChefSpec? #971

mrmarbury opened this issue Sep 16, 2019 · 1 comment

Comments

@mrmarbury
Copy link

I have a recipe that assembles a data bag item name depending on node.policy_group. Now I need a way to test this. My first idea is to simple mock the policy_group in my specs. But how would I do that? I didn't come across anything in the ChefSpec README. A hint is appreciated since we are currently in some kind of deadlock here and don't know how to test this at all. Testing this with test-kitchen seems very tedious.

@petracvv
Copy link

I've been banging my head against this for a while now but I think I have a way that works:

before do
  chef_runner.node.policy_group = <your-policy-group>
end

The above will mock the policy group in your chef run (for the recipe code to work)

If you need to access the policy group of the node in chefspec tests I think accessing it the same way (chef_runner.node.policy_group) will get you the value.

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

No branches or pull requests

2 participants