-
Notifications
You must be signed in to change notification settings - Fork 338
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 test edit_resource? #812
Comments
you gotta leave a more useful bug report. AFAIK it should be testable. there's bugs around use_inline_resources like #793 which need to get fixed or else a lot of the use cases for edit_resources will be broken, but that has nothing to do with edit_resources directly. |
Okay, i'll try to provide a specific example: # cookbook1::default
file '/tmp/test' do
content 'original content'
end
# cookbook2::default
edit_resource(:file, '/tmp/test') do
content 'super new content'
end the original file resource is easy testable, but how can i verify that I would think of something like: cached(:chef_run) { ChefSpec::ServerRunner.new.converge('cookbook2::default') }
...
expect(chef_run).to edit_resource(:template, '/etc/file').with(
content: 'super new content'
) … however cached(:chef_run) { ChefSpec::ServerRunner.new.converge('cookbook2::default') }
...
resource = chef_run.file('/etc/file')
expect(resource).to edit_resource('file[/etc/file]').with(
content: 'super new content'
) My goal is to explicity test the "edit_resource" action because usually I'll use it by modifying/wrapping external cookbooks. (updated) |
its exactly the same way. look for the file resource on the resource collection to have gotten constructed with the 'super new content' content. |
@tas50 i think this one is closable |
Unless there is a way to test those resource modifications, this issue isn't resolved and chefspec just lacks a feature to do to that...
|
you don't test the implementation details. testing this: file "/tmp/foo"
edit_resource(:file, "/tmp/foo") do
content "foo"
end is the same as testing this: file "/tmp/foo" do
content "foo"
end which in both cases is just this: it 'should install zsh package' do
expect(chef_run).to create_file('/tmp/foo').with(content: "foo")
end it doesn't matter if its written using edit_resource or not, what you're setting up expectations on is the final construction of the resource collection. how you get there is irrelevant. |
Recommended approach is to do not test library cookbook resources, excluding any library "include_recipe" appearances. Common pattern for using "edit_resource" is to edit resources that's defined in library, that we don't test. Chefspec drop failures, when it meets edit_resource with template/file from library cookbook. What's recommended way to use Chefspec in such situations? |
@olebel why not? |
Chef DSL's
edit_resource
should be test-able as well. see:What do you think?
The text was updated successfully, but these errors were encountered: