Merge pull request #9107 from chrisroberts/f-wsl-version-check
Check for vagrant.exe path before validating versions
This commit is contained in:
commit
fb4a1bf8e5
|
@ -447,18 +447,20 @@ module Vagrant
|
||||||
# are the same. Raise error if they do not match.
|
# are the same. Raise error if they do not match.
|
||||||
def wsl_validate_matching_vagrant_versions!
|
def wsl_validate_matching_vagrant_versions!
|
||||||
valid = false
|
valid = false
|
||||||
result = Util::Subprocess.execute("vagrant.exe", "version")
|
if Util::Which.which("vagrant.exe")
|
||||||
if result.exit_code == 0
|
result = Util::Subprocess.execute("vagrant.exe", "version")
|
||||||
windows_version = result.stdout.match(/Installed Version: (?<version>[\w.-]+)/)
|
if result.exit_code == 0
|
||||||
if windows_version
|
windows_version = result.stdout.match(/Installed Version: (?<version>[\w.-]+)/)
|
||||||
windows_version = windows_version[:version].strip
|
if windows_version
|
||||||
valid = windows_version == Vagrant::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
|
||||||
end
|
|
||||||
if !valid
|
|
||||||
raise Vagrant::Errors::WSLVagrantVersionMismatch,
|
|
||||||
wsl_version: Vagrant::VERSION,
|
|
||||||
windows_version: windows_version || "unknown"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -182,4 +182,36 @@ describe Vagrant::Util::Platform do
|
||||||
expect(subject.systemd?).to be_falsey
|
expect(subject.systemd?).to be_falsey
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue