Check for vagrant.exe path before validating versions

This commit is contained in:
Chris Roberts 2017-10-24 16:53:53 -07:00
parent 983313e8e5
commit d422053fbc
2 changed files with 45 additions and 11 deletions

View File

@ -447,18 +447,20 @@ module Vagrant
# are the same. Raise error if they do not match.
def wsl_validate_matching_vagrant_versions!
valid = false
result = Util::Subprocess.execute("vagrant.exe", "version")
if result.exit_code == 0
windows_version = result.stdout.match(/Installed Version: (?<version>[\w.-]+)/)
if windows_version
windows_version = windows_version[:version].strip
valid = windows_version == Vagrant::VERSION
if Util::Which.which("vagrant.exe")
result = Util::Subprocess.execute("vagrant.exe", "version")
if result.exit_code == 0
windows_version = result.stdout.match(/Installed Version: (?<version>[\w.-]+)/)
if windows_version
windows_version = windows_version[:version].strip
valid = windows_version == Vagrant::VERSION
end
end
if !valid
raise Vagrant::Errors::WSLVagrantVersionMismatch,
wsl_version: Vagrant::VERSION,
windows_version: windows_version || "unknown"
end
end
if !valid
raise Vagrant::Errors::WSLVagrantVersionMismatch,
wsl_version: Vagrant::VERSION,
windows_version: windows_version || "unknown"
end
end

View File

@ -182,4 +182,36 @@ describe Vagrant::Util::Platform do
expect(subject.systemd?).to be_falsey
end
end
describe ".wsl_validate_matching_vagrant_versions!" do
let(:exe_version){ Vagrant::VERSION.to_s }
before do
allow(Vagrant::Util::Which).to receive(:which).and_return(true)
allow(Vagrant::Util::Subprocess).to receive(:execute).with("vagrant.exe", "version").
and_return(double(exit_code: 0, stdout: "Installed Version: #{exe_version}"))
end
it "should not raise an error" do
Vagrant::Util::Platform.wsl_validate_matching_vagrant_versions!
end
context "when windows vagrant.exe is not installed" do
before{ expect(Vagrant::Util::Which).to receive(:which).with("vagrant.exe").and_return(nil) }
it "should not raise an error" do
Vagrant::Util::Platform.wsl_validate_matching_vagrant_versions!
end
end
context "when versions do not match" do
let(:exe_version){ "1.9.9" }
it "should raise an error" do
expect {
Vagrant::Util::Platform.wsl_validate_matching_vagrant_versions!
}.to raise_error(Vagrant::Errors::WSLVagrantVersionMismatch)
end
end
end
end