From 5ddecc5ec3ecc16f4b80f595d283ff5f77e47322 Mon Sep 17 00:00:00 2001 From: Pete Higgins Date: Tue, 7 Jul 2020 16:51:08 -0700 Subject: Fix systemd unit test on Windows. Signed-off-by: Pete Higgins --- spec/unit/provider/systemd_unit_spec.rb | 61 ++++++++++++++++++++------------- 1 file 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 -- cgit v1.2.1