Jeff Bonhag c52eb1b44c
Feature: ISO attachment for VirtualBox
This builds on the existing disk functionality, and adds some special
IDE controller-related flavor.

Considerations for IDE controllers:
- Primary/secondary attachments, so that each port can have two devices
  attached
- Adding the ability to address a specific controller name for disk
  attachment

This also prevents a user from attaching multiple instances of the same
ISO file, because VirtualBox will assign each of these the same UUID
which makes disconnection difficult. However, if multiple copies of the
ISO are attached to different devices, removing the DVD config will
cause the duplicate devices to be removed.

We may want to consider additional work to make the storage controllers
truly generic.
2020-07-09 15:07:27 -04:00

104 lines
2.6 KiB
Ruby

require File.expand_path("../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/kernel_v2/config/disk")
describe VagrantPlugins::Kernel_V2::VagrantConfigDisk do
include_context "unit"
let(:type) { :disk }
subject { described_class.new(type) }
let(:ui) { double("ui") }
let(:env) { double("env", ui: ui) }
let(:provider) { double("provider") }
let(:machine) { double("machine", name: "name", provider: provider, env: env,
provider_name: :virtualbox) }
def assert_invalid
errors = subject.validate(machine)
if errors.empty?
raise "No errors: #{errors.inspect}"
end
end
def assert_valid
errors = subject.validate(machine)
if !errors.empty?
raise "Errors: #{errors.inspect}"
end
end
before do
env = double("env")
subject.name = "foo"
subject.size = 100
allow(provider).to receive(:capability?).with(:validate_disk_ext).and_return(true)
allow(provider).to receive(:capability).with(:validate_disk_ext, "vdi").and_return(true)
allow(provider).to receive(:capability?).with(:set_default_disk_ext).and_return(true)
allow(provider).to receive(:capability).with(:set_default_disk_ext).and_return("vdi")
end
describe "with defaults" do
it "is valid with test defaults" do
subject.finalize!
assert_valid
end
it "sets a disk type" do
subject.finalize!
expect(subject.type).to eq(type)
end
it "defaults to non-primary disk" do
subject.finalize!
expect(subject.primary).to eq(false)
end
end
describe "with an invalid config" do
let(:invalid_subject) { described_class.new(type) }
it "raises an error if size not set" do
invalid_subject.name = "bar"
subject.finalize!
assert_invalid
end
context "with an invalid disk extension" do
before do
allow(provider).to receive(:capability?).with(:validate_disk_ext).and_return(true)
allow(provider).to receive(:capability).with(:validate_disk_ext, "fake").and_return(false)
end
it "raises an error" do
subject.finalize!
assert_invalid
end
end
end
describe "config for dvd type" do
let(:iso_path) { "/tmp/untitled.iso" }
before do
subject.type = :dvd
subject.name = "untitled"
end
it "is valid with file path set" do
allow(File).to receive(:file?).with(iso_path).and_return(true)
subject.file = iso_path
subject.finalize!
assert_valid
end
it "is invalid if file path is unset" do
subject.finalize!
errors = subject.validate(machine)
assert_invalid
end
end
end