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

Use of coerce in logrotate_app breaks specs #162

Open
rmoriz opened this issue Jan 14, 2022 · 1 comment
Open

Use of coerce in logrotate_app breaks specs #162

rmoriz opened this issue Jan 14, 2022 · 1 comment

Comments

@rmoriz
Copy link

rmoriz commented Jan 14, 2022

With the 3.0.0 changes introdoced in dc20786#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
Copy link
Contributor

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

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