Enforce unique names for disk config objects
This commit is contained in:
parent
b5b59a4eee
commit
734aad1ede
|
@ -812,7 +812,11 @@ module VagrantPlugins
|
||||||
name: machine.name)
|
name: machine.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Check for duplicate disk names?
|
disk_names = @disks.map { |d| d.name }
|
||||||
|
duplicate_names = disk_names.detect{ |d| disk_names.count(d) > 1 }
|
||||||
|
if duplicate_names && duplicate_names.size
|
||||||
|
errors << "Duplicate disk names found: #{duplicate_names}. Please use unique names"
|
||||||
|
end
|
||||||
|
|
||||||
@disks.each do |d|
|
@disks.each do |d|
|
||||||
error = d.validate(machine)
|
error = d.validate(machine)
|
||||||
|
|
|
@ -551,10 +551,12 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
|
|
||||||
describe "#disk" do
|
describe "#disk" do
|
||||||
it "stores the disks" do
|
it "stores the disks" do
|
||||||
subject.disk("disk", size: 100)
|
subject.disk(:disk, size: 100)
|
||||||
subject.disk("disk", size: 1000, primary: false, name: "storage")
|
subject.disk(:disk, size: 1000, primary: false, name: "storage")
|
||||||
subject.finalize!
|
subject.finalize!
|
||||||
|
|
||||||
|
assert_valid
|
||||||
|
|
||||||
d = subject.disks
|
d = subject.disks
|
||||||
expect(d.length).to eql(2)
|
expect(d.length).to eql(2)
|
||||||
expect(d[0].size).to eql(100)
|
expect(d[0].size).to eql(100)
|
||||||
|
@ -562,9 +564,16 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
expect(d[1].name).to eql("storage")
|
expect(d[1].name).to eql("storage")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises an error with duplicate names" do
|
||||||
|
subject.disk(:disk, size: 100, name: "foo")
|
||||||
|
subject.disk(:disk, size: 1000, name: "foo", primary: false)
|
||||||
|
subject.finalize!
|
||||||
|
assert_invalid
|
||||||
|
end
|
||||||
|
|
||||||
it "does not merge duplicate disks" do
|
it "does not merge duplicate disks" do
|
||||||
subject.disk("disk", size: 1000, primary: false, name: "storage")
|
subject.disk(:disk, size: 1000, primary: false, name: "storage")
|
||||||
subject.disk("disk", size: 1000, primary: false, name: "backup")
|
subject.disk(:disk, size: 1000, primary: false, name: "backup")
|
||||||
|
|
||||||
merged = subject.merge(subject)
|
merged = subject.merge(subject)
|
||||||
merged_disks = merged.disks
|
merged_disks = merged.disks
|
||||||
|
@ -573,10 +582,10 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores non-overriding runs" do
|
it "ignores non-overriding runs" do
|
||||||
subject.disk("disk", name: "foo")
|
subject.disk(:disk, name: "foo")
|
||||||
|
|
||||||
other = described_class.new
|
other = described_class.new
|
||||||
other.disk("disk", name: "bar", primary: false)
|
other.disk(:disk, name: "bar", primary: false)
|
||||||
|
|
||||||
merged = subject.merge(other)
|
merged = subject.merge(other)
|
||||||
merged_disks = merged.disks
|
merged_disks = merged.disks
|
||||||
|
|
Loading…
Reference in New Issue