diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-07-07 16:51:08 -0700 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-07-07 16:51:08 -0700 |
commit | 5ddecc5ec3ecc16f4b80f595d283ff5f77e47322 (patch) | |
tree | a2dfe20b2c6b033e947abbb3d0d07b94bfc3fd80 | |
parent | 8dfb972e9dd8c760b453d76b5db73f1f8b96ecb0 (diff) | |
download | chef-fix-systemd-unit-test-on-windows.tar.gz |
Fix systemd unit test on Windows.fix-systemd-unit-test-on-windows
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r-- | spec/unit/provider/systemd_unit_spec.rb | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb index cf26c99b77..b13ca9448b 100644 --- a/spec/unit/provider/systemd_unit_spec.rb +++ b/spec/unit/provider/systemd_unit_spec.rb @@ -220,31 +220,44 @@ describe Chef::Provider::SystemdUnit do expect(current_resource.content).to eq(nil) end - it "loads the user unit content if the file exists and user is set" do - new_resource.user("joe") - allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(true) - allow(File).to receive(:read) - .with(unit_path_user) - .and_return(unit_content_string) - expect(File).to receive(:exist?) - .with(unit_path_user) - expect(File).to receive(:read) - .with(unit_path_user) - provider.load_current_resource - expect(current_resource.content).to eq(unit_content_string) - end + if windows? + it "fails when attempting to set the user on Windows" do + new_resource.user("joe") + allow(File).to receive(:exist?) + .with(unit_path_user) + .and_return(false) + expect(File).to_not receive(:read) + .with(unit_path_user) + + expect { provider.load_current_resource }.to raise_error(Mixlib::ShellOut::InvalidCommandOption) + end + else + it "loads the user unit content if the file exists and user is set" do + new_resource.user("joe") + allow(File).to receive(:exist?) + .with(unit_path_user) + .and_return(true) + allow(File).to receive(:read) + .with(unit_path_user) + .and_return(unit_content_string) + expect(File).to receive(:exist?) + .with(unit_path_user) + expect(File).to receive(:read) + .with(unit_path_user) + provider.load_current_resource + expect(current_resource.content).to eq(unit_content_string) + end - it "does not load the user unit if the file does not exist and user is set" do - new_resource.user("joe") - allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(false) - expect(File).to_not receive(:read) - .with(unit_path_user) - provider.load_current_resource - expect(current_resource.content).to eq(nil) + it "does not load the user unit if the file does not exist and user is set" do + new_resource.user("joe") + allow(File).to receive(:exist?) + .with(unit_path_user) + .and_return(false) + expect(File).to_not receive(:read) + .with(unit_path_user) + provider.load_current_resource + expect(current_resource.content).to eq(nil) + end end end |