Skip to content

Commit

Permalink
Add test cases for event state machines.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Jan 24, 2018
1 parent 1535271 commit 56ad2bd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_domain_file

describe ManageIQ::Automate::System::Event::StateMachines::Refresh::CheckRefreshed do
let(:event) { FactoryGirl.create(:event_stream) }
let(:task) { FactoryGirl.create(:miq_task) }

let(:svc_event) { MiqAeMethodService::MiqAeServiceEventStream.find(event.id) }
let(:svc_task) { MiqAeMethodService::MiqAeServiceMiqTask.find(task.id) }

let(:ae_service) do
Spec::Support::MiqAeMockService.new(Spec::Support::MiqAeMockObject.new({})).tap do |service|
current_object = Spec::Support::MiqAeMockObject.new
current_object.parent = Spec::Support::MiqAeMockObject.new({})
service.object = current_object
end
end

it 'when task is finished with "ok"' do
ae_service.set_state_var(:refresh_task_id, [task.id])
task.update_attributes(:state => 'Finished')
described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq('ok')
end

it 'when task is finished with "error"' do
ae_service.set_state_var(:refresh_task_id, [task.id])
task.update_attributes(:state => 'Finished', :status => 'Timeout')
described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq('error')
end

it 'when task is active' do
ae_service.set_state_var(:refresh_task_id, [task.id])
task.update_attributes(:state => 'Active')
described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq('retry')
expect(ae_service.root['ae_retry_interval']).to eq('1.minute')
end

it 'when specified task does not exist' do
ae_service.set_state_var(:refresh_task_id, [99])
expect { described_class.new(ae_service).main }.to raise_error('Refresh task with id: 99 not found')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require_domain_file

describe ManageIQ::Automate::System::Event::StateMachines::Refresh::TargetRefresh do
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => ems) }
let(:event) { FactoryGirl.create(:ems_event, :vm_or_template => vm) }
let(:svc_event) { MiqAeMethodService::MiqAeServiceEventStream.find(event.id) }
let(:root_object) { Spec::Support::MiqAeMockObject.new('event_stream' => event) }
let(:ae_service) do
Spec::Support::MiqAeMockService.new(root_object).tap do |service|
service.object = Spec::Support::MiqAeMockObject.new('refresh_target' => 'src_vm')
end
end

it 'when event object is not found' do
ae_service.root['event_stream'] = nil
expect { described_class.new(ae_service).main }.to raise_error(RuntimeError, "Event object not found")
end

it 'when refresh target is specified' do
described_class.new(ae_service).main
expect(ae_service.get_state_var(:refresh_task_id)).to be_truthy
end

it 'when refresh target is not specified' do
ae_service.object['refresh_target'] = nil
expect { described_class.new(ae_service).main }.to raise_error(RuntimeError, "Refresh target not found")
end

it 'when specified target does not exist' do
ae_service.object['refresh_target'] = 'src_host'
expect { described_class.new(ae_service).main }.to raise_error(RuntimeError, "Refresh task not created")
end
end

0 comments on commit 56ad2bd

Please sign in to comment.