Merge pull request #9107 from chrisroberts/f-wsl-version-check

Check for vagrant.exe path before validating versions
This commit is contained in:
Chris Roberts 2017-11-02 12:58:05 -07:00 committed by GitHub
commit fb4a1bf8e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 11 deletions

View File

@ -447,6 +447,7 @@ module Vagrant
# are the same. Raise error if they do not match.
def wsl_validate_matching_vagrant_versions!
valid = false
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.-]+)/)
@ -461,6 +462,7 @@ module Vagrant
windows_version: windows_version || "unknown"
end
end
end
# systemd is in use
def systemd?

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