-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for event state machines.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
34 changes: 34 additions & 0 deletions
34
...mate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |