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 23, 2018
1 parent dd72d5d commit 51c2755
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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' 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 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 task id is not set' do
expect { described_class.new(ae_service).main }.to raise_error('Refresh task id is nil')
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

0 comments on commit 51c2755

Please sign in to comment.