Skip to content

Commit

Permalink
add ae ansible workflow template specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nasark committed Sep 6, 2024
1 parent 0dd2439 commit d32c864
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions spec/miq_ae_ansible_template_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let(:miq_task) { FactoryBot.create(:miq_task) }
let(:manager) { FactoryBot.create(:automation_manager_ansible_tower) }
let(:template) { FactoryBot.create(:ansible_configuration_script, :manager => manager) }
let(:workflow_template) { FactoryBot.create(:ansible_configuration_workflow, :manager => manager) }

let(:workspace) do
double("MiqAeEngine::MiqAeWorkspaceRuntime", :root => root_object,
Expand Down Expand Up @@ -106,7 +107,7 @@
end
end

context "regular method" do
context "regular method with jobs" do
before do
allow(described_class::TEMPLATE_CLASS).to receive(:find).and_return(template)
allow(template).to receive(:run_with_miq_job).and_return(miq_task.id)
Expand All @@ -133,7 +134,7 @@
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "template launch fails" do
it "job template launch fails" do
expect(template).to receive(:run_with_miq_job).and_raise("Bamm Bamm Rubble")

at = described_class.new(aem, obj, inputs)
Expand All @@ -142,6 +143,42 @@
end
end

context "regular method with workflows" do
before do
allow(described_class::TEMPLATE_CLASS).to receive(:find).and_return(workflow_template)
allow(workflow_template).to receive(:run_with_miq_job).and_return(miq_task.id)
allow(MiqRegion).to receive(:my_region).and_return(FactoryBot.create(:miq_region))
allow(AutomateWorkspace).to receive(:create).and_return(aw)
allow(MiqTask).to receive(:wait_for_taskid).and_return(miq_task)
allow(workspace).to receive(:update_workspace)
end

it "success" do
miq_task.update_status(MiqTask::STATE_FINISHED, MiqTask::STATUS_OK, "Done")

at = described_class.new(aem, obj, inputs)
at.run

expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "method fails" do
miq_task.update_status(MiqTask::STATE_FINISHED, MiqTask::STATUS_ERROR, "Done")

at = described_class.new(aem, obj, inputs)
expect { at.run }.to raise_exception(MiqAeException::Error)
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "workflow template launch fails" do
expect(workflow_template).to receive(:run_with_miq_job).and_raise("Bamm Bamm Rubble")

at = described_class.new(aem, obj, inputs)
expect { at.run }.to raise_exception(MiqAeException::Error)
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end
end

context "state machine" do
before do
root_hash['ae_state_started'] = Time.zone.now.utc.to_s
Expand Down

0 comments on commit d32c864

Please sign in to comment.