test/unit/vagrant/util/platform_test.rb in vagrant-unbundled-2.0.0.1 vs test/unit/vagrant/util/platform_test.rb in vagrant-unbundled-2.0.1.0

- old
+ new

@@ -20,14 +20,40 @@ it "takes a windows path and returns a formatted path" do allow(Vagrant::Util::Which).to receive(:which).and_return("C:/msys2/cygpath") allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(subprocess_result) + expect(Vagrant::Util::Subprocess).to receive(:execute).with("C:\\msys2\\cygpath", "-u", "-a", "C:\\msys2\\home\\vagrant") + expect(subject.cygwin_path(path)).to eq("/home/vagrant") end end + describe "#msys_path" do + let(:updated_path) { "/home/vagrant" } + let(:subprocess_result) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(0) + allow(result).to receive(:stdout).and_return(updated_path) + end + end + let(:old_path) { "/old/path/bin:/usr/local/bin:/usr/bin" } + + it "takes a windows path and returns a formatted path" do + path = ENV["PATH"] + allow(Vagrant::Util::Which).to receive(:which).and_return("C:/msys2/cygpath") + allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(subprocess_result) + allow(ENV).to receive(:[]).with("PATH").and_return(path) + allow(ENV).to receive(:[]).with("VAGRANT_OLD_ENV_PATH").and_return(old_path) + + expect(Vagrant::Util::Subprocess).to receive(:execute).with("C:\\msys2\\cygpath", "-u", "-a", path) + + expect(subject.msys_path(path)).to eq("/home/vagrant") + expect(ENV["PATH"]).to eq(path) + end + end + describe "#cygwin?" do before do allow(subject).to receive(:platform).and_return("test") described_class.reset! end @@ -152,8 +178,40 @@ end it "should return false if systemd is not in use" do expect(Vagrant::Util::Subprocess).to receive(:execute).and_return(double(:result, stdout: "other")) 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