sous-chefs / logrotate

Development repository for the logrotate cookbook
https://supermarket.chef.io/cookbooks/logrotate
Apache License 2.0
122 stars 151 forks source link

Use of coerce in logrotate_app breaks specs #162

Open rmoriz opened 2 years ago

rmoriz commented 2 years ago

With the 3.0.0 changes introdoced in https://github.com/sous-chefs/logrotate/commit/dc20786df1b23734379aaaf7cde03dfbcb4c96e7#diff-b7e94f5fcd66051355907f23b26ff6ac96685ca36c95837931a588074999fbf9R26 it's a lot harder to write chefspecs when a logrotate_app resource is called with an paths array

e.g.

logrotate_app 'nginx' do                                             
  cookbook 'logrotate'                                                       
  path [                                                           
    "#{node['web']['root']}/logs/ssl-access.log",
    "#{node['web']['root']}/logs/ssl-error.log"
  ]
...
end 

In older versions when coerce was not used, one could simply write the following chef spec:

  it 'add logrotation' do
    expect(chef_run).to enable_logrotate_app('nginx').with(
      path: [
        "/path/to/www/logs/ssl-access.log",
        "/path/to/www/logs/ssl-error.log",
      ],
...
    )
  end

As coerce merges the array on assignment, this does not work anymore. The workaround is to "deal with the internals" and format the paths as a coerced string like

  it 'add logrotation' do
    expect(chef_run).to enable_logrotate_app('nginx').with(
      path: '"/path/to/www/logs/ssl-access.log" "/path/to/www/logs/ssl-error.log"',
    ...
    )
  end

which is obviously ugly and does not represent the way, the resource is called in the recipe. Any idea to make this usable again?

Thank you.

ramereth commented 2 years ago

Yeah unfortunately that's what you need to do when using ChefSpec.