vaguerent/test/unit/vagrant/util/powershell_test.rb
Chris Roberts 90fa705a6d Make powershell version detection timeout configurable
Allows custom configuration of the powershell timeout and bumps
the default timeout from 10 seconds to 30 seconds.

Fixes #9629
2018-04-04 16:02:11 -07:00

45 lines
1.5 KiB
Ruby

require File.expand_path("../../../base", __FILE__)
require 'vagrant/util/powershell'
describe Vagrant::Util::PowerShell do
include_context "unit"
describe ".version" do
before do
allow(described_class).to receive(:executable)
.and_return("powershell")
allow(Vagrant::Util::Subprocess).to receive(:execute)
end
after do
described_class.version
described_class.reset!
end
it "should execute powershell command" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with("powershell", any_args)
end
it "should use the default timeout" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
end
it "should use environment variable provided timeout" do
with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "1") do
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
timeout: 1))
described_class.version
end
end
it "should use default timeout when environment variable value is invalid" do
with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "invalid value") do
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
described_class.version
end
end
end
end