(POOLER-73) Modify spec tests for _check_pending_vm

(POOLER-73) Modify spec tests for _check_pending_vm
This commit is contained in:
Glenn Sarti 2017-02-08 17:00:12 -08:00
parent b72275b552
commit 9fdb51eb00

View file

@ -86,33 +86,34 @@ describe 'Pool Manager' do
end end
describe '#_check_pending_vm' do describe '#_check_pending_vm' do
let(:pool_helper) { double('pool') } let(:vsphere) { double('vsphere') }
let(:vsphere) { {pool => pool_helper} }
before do before do
expect(subject).not_to be_nil expect(subject).not_to be_nil
$vsphere = vsphere
end end
context 'host not in pool' do context 'host does not exist or not in pool' do
it 'calls fail_pending_vm' do it 'calls fail_pending_vm' do
allow(vsphere).to receive(:find_vm).and_return(nil) expect(vsphere).to receive(:find_vm).and_return(nil)
allow(redis).to receive(:hget) expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout, false)
subject._check_pending_vm(vm, pool, timeout, vsphere) subject._check_pending_vm(vm, pool, timeout, vsphere)
end end
end end
context 'host is in pool' do context 'host is in pool' do
let(:vm_finder) { double('vm_finder') } it 'calls move_pending_vm_to_ready if host is ready' do
let(:tcpsocket) { double('TCPSocket') } expect(vsphere).to receive(:find_vm).and_return(host)
expect(subject).to receive(:open_socket).and_return(nil)
expect(subject).to receive(:move_pending_vm_to_ready).with(vm, pool, host)
it 'calls move_pending_vm_to_ready' do subject._check_pending_vm(vm, pool, timeout, vsphere)
allow(subject).to receive(:open_socket).and_return(true) end
allow(vsphere).to receive(:find_vm).and_return(vm_finder)
allow(vm_finder).to receive(:summary).and_return(nil)
expect(vm_finder).to receive(:summary).once it 'calls fail_pending_vm if an error is raised' do
expect(redis).not_to receive(:hget).with(String, 'clone') expect(vsphere).to receive(:find_vm).and_return(host)
expect(subject).to receive(:open_socket).and_raise(SocketError,'getaddrinfo: No such host is known')
expect(subject).to receive(:fail_pending_vm).with(vm, pool, timeout)
subject._check_pending_vm(vm, pool, timeout, vsphere) subject._check_pending_vm(vm, pool, timeout, vsphere)
end end