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

Call to Win32::Service causes rake unit to fail on Linux #73

Open
thedeafduck opened this issue Sep 25, 2020 · 0 comments
Open

Call to Win32::Service causes rake unit to fail on Linux #73

thedeafduck opened this issue Sep 25, 2020 · 0 comments

Comments

@thedeafduck
Copy link

thedeafduck commented Sep 25, 2020

I have a cookbook that is used on both Linux and Windows platforms. In one of the recipes, that is only called if the cookbook is executed on Windows, we have:

service 'MyService' do
  action %i[enable start]
  only_if { ::Win32::Service.exists?("MyService") }
  not_if { ::File.exist?("#{install_dir}\\scripts\\instance-stopped") }
end

on Windows, rake unit works perfectly. Also, running the cookbook via a converge on either Linux or Windows also works perfectly. However, the rake unit on Linux fails with:

Failures:

myagent::install_windows When set to install agent on Windows converges successfully Failure/Error: expect { chef_run }.to_not raise_error

expected no Exception, got #<NameError: uninitialized constant Win32> with backtrace: # /tmp/chefspec20200924-2530-350e0zfile_cache_path/cookbooks/myagent/resources/install_agent.rb:83:in `block (3 levels) in class_from_file'

I have tried adding:

allow(::Win32::Service).to receive(:exists?).with(windows_service[:name]).and_return(true)

to the spec file, but this then causes the rake unit to fail on Windows and Linux.

Is there a way of telling the spec file to only use a line like the allow if we are on Linux?

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

1 participant