Clean up tests

This commit is contained in:
Chris Roberts 2018-01-02 14:36:56 -08:00
parent 3eeff59329
commit 3e4c81f6b1
3 changed files with 38 additions and 5 deletions

View File

@ -65,7 +65,23 @@ describe VagrantPlugins::HostDarwin::Cap::SMB do
expect{ subject.smb_start(env) }.to raise_error(VagrantPlugins::SyncedFolderSMB::Errors::SMBStartFailed) expect{ subject.smb_start(env) }.to raise_error(VagrantPlugins::SyncedFolderSMB::Errors::SMBStartFailed)
end 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 end
describe ".smb_cleanup" do describe ".smb_cleanup" do

View File

@ -9,10 +9,27 @@ describe VagrantPlugins::HostWindows::Cap::SMB do
let(:options){ {} } let(:options){ {} }
let(:result){ Vagrant::Util::Subprocess::Result } let(:result){ Vagrant::Util::Subprocess::Result }
let(:powershell_version){ "3" } 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 before do
allow(subject).to receive(:machine_id).and_return("CUSTOM_ID") 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(:version).and_return(powershell_version)
allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).and_return("")
allow(machine.env.ui).to receive(:warn) allow(machine.env.ui).to receive(:warn)
allow(subject).to receive(:sleep) allow(subject).to receive(:sleep)
end end
@ -35,8 +52,8 @@ describe VagrantPlugins::HostWindows::Cap::SMB do
describe ".smb_cleanup" do describe ".smb_cleanup" do
before do before do
allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).with("net share"). allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).with(/Get-SmbShare/).
and_return("vgt-CUSTOM_ID-1\nvgt-CUSTOM_ID-2\n") and_return(smblist)
allow(Vagrant::Util::PowerShell).to receive(:execute).and_return(result.new(0, "", "")) allow(Vagrant::Util::PowerShell).to receive(:execute).and_return(result.new(0, "", ""))
end end
after{ subject.smb_cleanup(env, machine, options) } after{ subject.smb_cleanup(env, machine, options) }
@ -52,7 +69,7 @@ describe VagrantPlugins::HostWindows::Cap::SMB do
context "when no shares are defined" do context "when no shares are defined" do
before 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("") and_return("")
end end

View File

@ -88,7 +88,7 @@ describe VagrantPlugins::SyncedFolderSMB::SyncedFolder do
end end
it "should start the SMB service if capability is available" do 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) subject.prepare(machine, folders, options)
end end
end end