diff --git a/test/unit/plugins/hosts/darwin/cap/smb_test.rb b/test/unit/plugins/hosts/darwin/cap/smb_test.rb index a0ea44bcd..5d5884bc9 100644 --- a/test/unit/plugins/hosts/darwin/cap/smb_test.rb +++ b/test/unit/plugins/hosts/darwin/cap/smb_test.rb @@ -65,7 +65,23 @@ describe VagrantPlugins::HostDarwin::Cap::SMB do expect{ subject.smb_start(env) }.to raise_error(VagrantPlugins::SyncedFolderSMB::Errors::SMBStartFailed) end - # TODO Finish out last start coverage + it "should not load smbd if it is already loaded" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with("launchctl", "list", /smbd/).and_return(result.new(0, "", "")) + expect(Vagrant::Util::Subprocess).not_to receive(:execute).with(/sudo/, /launchctl/, "load", "-w", /smbd/) + subject.smb_start(env) + end + + it "should load smbd if it is not already loaded" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with("launchctl", "list", /smbd/).and_return(result.new(1, "", "")) + expect(Vagrant::Util::Subprocess).to receive(:execute).with(/sudo/, /launchctl/, "load", "-w", /smbd/).and_return(result.new(0, "", "")) + subject.smb_start(env) + end + + it "should raise error if load smbd fails" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with("launchctl", "list", /smbd/).and_return(result.new(1, "", "")) + expect(Vagrant::Util::Subprocess).to receive(:execute).with(/sudo/, /launchctl/, "load", "-w", /smbd/).and_return(result.new(1, "", "")) + expect{ subject.smb_start(env) }.to raise_error(VagrantPlugins::SyncedFolderSMB::Errors::SMBStartFailed) + end end describe ".smb_cleanup" do diff --git a/test/unit/plugins/hosts/windows/cap/smb_test.rb b/test/unit/plugins/hosts/windows/cap/smb_test.rb index 20c09d1ef..216be6397 100644 --- a/test/unit/plugins/hosts/windows/cap/smb_test.rb +++ b/test/unit/plugins/hosts/windows/cap/smb_test.rb @@ -9,10 +9,27 @@ describe VagrantPlugins::HostWindows::Cap::SMB do let(:options){ {} } let(:result){ Vagrant::Util::Subprocess::Result } let(:powershell_version){ "3" } + let(:smblist){ <<-EOF +Name : vgt-CUSTOM_ID-1 +Path : /a/path +Description : vgt-CUSTOM_ID-1 + +Name : vgt-CUSTOM_ID-2 +Path : /other/path +Description : vgt-CUSTOM_ID-2 + +Name : my-share +Path : /my/path +Description : Not Vagrant Owned + + EOF + } + before do allow(subject).to receive(:machine_id).and_return("CUSTOM_ID") allow(Vagrant::Util::PowerShell).to receive(:version).and_return(powershell_version) + allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).and_return("") allow(machine.env.ui).to receive(:warn) allow(subject).to receive(:sleep) end @@ -35,8 +52,8 @@ describe VagrantPlugins::HostWindows::Cap::SMB do describe ".smb_cleanup" do before do - allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).with("net share"). - and_return("vgt-CUSTOM_ID-1\nvgt-CUSTOM_ID-2\n") + allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).with(/Get-SmbShare/). + and_return(smblist) allow(Vagrant::Util::PowerShell).to receive(:execute).and_return(result.new(0, "", "")) end after{ subject.smb_cleanup(env, machine, options) } @@ -52,7 +69,7 @@ describe VagrantPlugins::HostWindows::Cap::SMB do context "when no shares are defined" do before do - expect(Vagrant::Util::PowerShell).to receive(:execute_cmd).with("net share"). + expect(Vagrant::Util::PowerShell).to receive(:execute_cmd).with(/Get-SmbShare/). and_return("") end diff --git a/test/unit/plugins/synced_folders/smb/synced_folder_test.rb b/test/unit/plugins/synced_folders/smb/synced_folder_test.rb index b01902df8..a80d45a3a 100644 --- a/test/unit/plugins/synced_folders/smb/synced_folder_test.rb +++ b/test/unit/plugins/synced_folders/smb/synced_folder_test.rb @@ -88,7 +88,7 @@ describe VagrantPlugins::SyncedFolderSMB::SyncedFolder do end it "should start the SMB service if capability is available" do - expect(host).to receive(:capability).with(:smb_install, any_args) + expect(host).to receive(:capability).with(:smb_start, any_args) subject.prepare(machine, folders, options) end end