mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Fix assert_invalid in configuration spec
assert_invalid was previously only raising an error if there was a validation error logged, rather than if there wasn't an error. Tests that expected validation failures were passing without any validation errors being logged.
This commit is contained in:
parent
772c38a2b3
commit
7b968c7a72
@ -8,7 +8,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
|
||||
def assert_invalid
|
||||
errors = subject.validate(machine)
|
||||
raise "No errors: #{errors.inspect}" if errors.values.any? { |v| !v.empty? }
|
||||
raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
|
||||
end
|
||||
|
||||
def assert_valid
|
||||
@ -21,6 +21,9 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
assert_valid
|
||||
end
|
||||
|
||||
context 'with disks defined' do
|
||||
before { expect(machine).to receive(:provider_config).and_return(subject).at_least(:once) }
|
||||
|
||||
it 'is valid if relative path used for disk' do
|
||||
subject.storage :file, path: '../path/to/file.qcow2'
|
||||
assert_valid
|
||||
@ -30,22 +33,19 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
subject.storage :file, path: '/absolute/path/to/file.qcow2'
|
||||
assert_invalid
|
||||
end
|
||||
end
|
||||
|
||||
context 'with mac defined' do
|
||||
let (:vm) { double('vm') }
|
||||
let (:networks) { double('networks') }
|
||||
before do
|
||||
allow(vm).to receive(:networks).and_return(networks)
|
||||
allow(machine.config).to receive(:vm).and_return(vm)
|
||||
end
|
||||
before { expect(machine.config).to receive(:vm).and_return(vm) }
|
||||
|
||||
it 'is valid with valid mac' do
|
||||
allow(networks).to receive(:each).and_return([:public, { mac: 'aa:bb:cc:dd:ee:ff' }])
|
||||
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa:bb:cc:dd:ee:ff' }]])
|
||||
assert_valid
|
||||
end
|
||||
|
||||
it 'should be invalid if MAC not formatted correctly' do
|
||||
allow(networks).to receive(:each).and_return([:public, { mac: 'aabbccddeeff' }])
|
||||
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aabbccddeeff' }]])
|
||||
assert_invalid
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user