Skip to content

Commit

Permalink
added test coverage for assigning Vm#ems_created_on field
Browse files Browse the repository at this point in the history
  • Loading branch information
yrudman committed Aug 27, 2019
1 parent a0bf167 commit 4c6670e
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions spec/models/vm_or_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,22 +618,45 @@
end
end

describe "#assign_ems_created_on_queue" do
it "queuing task to execute 'assign_ems_created_on' on server with 'ems_operations' role" do
expect(MiqQueue).to receive(:submit_job).with(
:class_name => described_class.name,
:method_name => 'assign_ems_created_on',
:role => 'ems_operations',
:args => [vm.id],
:priority => MiqQueue::MIN_PRIORITY
)
described_class.assign_ems_created_on_queue(vm.id)
end
end

describe "assign_ems_created_on" do
it "assigns timestamp on `VmDeployedEvent` event to `vm#ems_created_on field " do
timestamp = Time.now.utc.change(:usec => 0)
FactoryBot.create(:ems_event, :event_type => "VmDeployedEvent", :dest_vm_or_template => vm, :timestamp => timestamp)
described_class.assign_ems_created_on(vm.id)
expect(vm.reload.ems_created_on.utc).to eq(timestamp)
end
end

it "with ems_events" do
ems = FactoryBot.create(:ems_vmware_with_authentication)
vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems)
ems_event_src = FactoryBot.create(:ems_event, :vm_or_template => vm)
ems = FactoryBot.create(:ems_vmware_with_authentication)
vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems)
ems_event_src = FactoryBot.create(:ems_event, :vm_or_template => vm)
ems_event_dest = FactoryBot.create(:ems_event, :dest_vm_or_template => vm)

expect(vm.ems_events.count).to eq(2)
expect(vm.ems_events_src.first).to be_kind_of(EmsEvent)
expect(vm.ems_events_src.first.id).to eq(ems_event_src.id)
#expect(vm.ems_events_src.first).to be_kind_of(EmsEvent)
#expect(vm.ems_events_src.first.id).to eq(ems_event_src.id)
expect(vm.ems_events_src.first).to eq(ems_event_src)
expect(vm.ems_events_dest.first.id).to eq(ems_event_dest.id)
end

it "#miq_provision_vms" do
ems = FactoryBot.create(:ems_vmware_with_authentication)
template = FactoryBot.create(:template_vmware, :ext_management_system => ems)
vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems)
ems = FactoryBot.create(:ems_vmware_with_authentication)
template = FactoryBot.create(:template_vmware, :ext_management_system => ems)
vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems)

options = {
:vm_name => vm.name,
Expand Down

0 comments on commit 4c6670e

Please sign in to comment.