2014-02-16 00:28:11 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/providers/hyperv/provider")
|
|
|
|
|
|
|
|
describe VagrantPlugins::HyperV::Provider do
|
|
|
|
let(:machine) { double("machine") }
|
2014-02-16 01:06:26 +00:00
|
|
|
let(:platform) { double("platform") }
|
2014-02-16 00:28:11 +00:00
|
|
|
let(:powershell) { double("powershell") }
|
|
|
|
|
|
|
|
subject { described_class.new(machine) }
|
|
|
|
|
|
|
|
before do
|
2014-02-16 01:06:26 +00:00
|
|
|
stub_const("Vagrant::Util::Platform", platform)
|
2014-02-16 00:28:11 +00:00
|
|
|
stub_const("Vagrant::Util::PowerShell", powershell)
|
2014-03-06 17:04:23 +00:00
|
|
|
machine.stub(id: "foo")
|
2014-02-16 01:06:26 +00:00
|
|
|
platform.stub(windows?: true)
|
|
|
|
platform.stub(windows_admin?: true)
|
2015-12-10 15:04:39 +00:00
|
|
|
platform.stub(windows_hyperv_admin?: true)
|
2014-02-16 00:28:11 +00:00
|
|
|
powershell.stub(available?: true)
|
|
|
|
end
|
|
|
|
|
2014-04-10 17:45:48 +00:00
|
|
|
describe ".usable?" do
|
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
it "returns false if not windows" do
|
|
|
|
platform.stub(windows?: false)
|
|
|
|
expect(subject).to_not be_usable
|
|
|
|
end
|
|
|
|
|
2015-12-10 15:04:39 +00:00
|
|
|
it "returns false if neither an admin nor a hyper-v admin" do
|
2014-04-10 17:45:48 +00:00
|
|
|
platform.stub(windows_admin?: false)
|
2015-12-10 15:04:39 +00:00
|
|
|
platform.stub(windows_hyperv_admin?: false)
|
2014-04-10 17:45:48 +00:00
|
|
|
expect(subject).to_not be_usable
|
|
|
|
end
|
|
|
|
|
2015-12-10 15:04:39 +00:00
|
|
|
it "returns true if not an admin but is a hyper-v admin" do
|
|
|
|
platform.stub(windows_admin?: false)
|
|
|
|
platform.stub(windows_hyperv_admin?: true)
|
|
|
|
expect(subject).to be_usable
|
|
|
|
end
|
|
|
|
|
2014-04-10 17:45:48 +00:00
|
|
|
it "returns false if powershell is not available" do
|
|
|
|
powershell.stub(available?: false)
|
|
|
|
expect(subject).to_not be_usable
|
|
|
|
end
|
|
|
|
|
2014-02-16 01:06:26 +00:00
|
|
|
it "raises an exception if not windows" do
|
|
|
|
platform.stub(windows?: false)
|
|
|
|
|
2014-04-10 17:45:48 +00:00
|
|
|
expect { subject.usable?(true) }.
|
2014-02-16 01:06:26 +00:00
|
|
|
to raise_error(VagrantPlugins::HyperV::Errors::WindowsRequired)
|
|
|
|
end
|
|
|
|
|
2015-12-10 15:04:39 +00:00
|
|
|
it "raises an exception if neither an admin nor a hyper-v admin" do
|
|
|
|
platform.stub(windows_admin?: false)
|
|
|
|
platform.stub(windows_hyperv_admin?: false)
|
|
|
|
|
|
|
|
expect { subject.usable?(true) }.
|
|
|
|
to raise_error(VagrantPlugins::HyperV::Errors::AdminRequired)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception if neither an admin nor a hyper-v admin" do
|
2014-02-16 01:06:26 +00:00
|
|
|
platform.stub(windows_admin?: false)
|
2015-12-10 15:04:39 +00:00
|
|
|
platform.stub(windows_hyperv_admin?: false)
|
2014-02-16 01:06:26 +00:00
|
|
|
|
2014-04-10 17:45:48 +00:00
|
|
|
expect { subject.usable?(true) }.
|
2014-02-16 01:06:26 +00:00
|
|
|
to raise_error(VagrantPlugins::HyperV::Errors::AdminRequired)
|
|
|
|
end
|
|
|
|
|
2014-02-16 00:28:11 +00:00
|
|
|
it "raises an exception if powershell is not available" do
|
|
|
|
powershell.stub(available?: false)
|
|
|
|
|
2014-04-10 17:45:48 +00:00
|
|
|
expect { subject.usable?(true) }.
|
2014-02-16 00:28:11 +00:00
|
|
|
to raise_error(VagrantPlugins::HyperV::Errors::PowerShellRequired)
|
|
|
|
end
|
|
|
|
end
|
2014-02-16 02:13:39 +00:00
|
|
|
|
|
|
|
describe "#driver" do
|
|
|
|
it "is initialized" do
|
|
|
|
expect(subject.driver).to be_kind_of(VagrantPlugins::HyperV::Driver)
|
|
|
|
end
|
|
|
|
end
|
2014-02-16 19:31:33 +00:00
|
|
|
|
|
|
|
describe "#state" do
|
|
|
|
it "returns not_created if no ID" do
|
|
|
|
machine.stub(id: nil)
|
|
|
|
|
|
|
|
expect(subject.state.id).to eq(:not_created)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls an action to determine the ID" do
|
|
|
|
machine.stub(id: "foo")
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(machine).to receive(:action).with(:read_state).
|
2014-02-16 19:31:33 +00:00
|
|
|
and_return({ machine_state_id: :bar })
|
|
|
|
|
|
|
|
expect(subject.state.id).to eq(:bar)
|
|
|
|
end
|
|
|
|
end
|
2014-02-16 00:28:11 +00:00
|
|
|
end
|