Skip to content

Commit

Permalink
Add specs for other ways that automate methods can exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy authored and jrafanie committed Mar 29, 2018
1 parent 3da93b0 commit df20f49
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions spec/lib/miq_automation_engine/engine/miq_ae_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ def current_method; "/my/automate/method"; end

subject { described_class.send(:invoke_inline_ruby, aem, obj, inputs) }

context "with a script that ends normally" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
RUBY
end

it "logs and returns the correct exit status" do
allow($miq_ae_logger).to receive(:info).and_call_original
expect($miq_ae_logger).to receive(:info).with("Method exited with rc=MIQ_OK").at_least(:once)
expect($miq_ae_logger).to_not receive(:error)

expect(subject).to eq(0)
end
end

context "with a script that raises" do
let(:script) do
<<-RUBY
Expand Down Expand Up @@ -54,6 +70,102 @@ def my_method
end
end

context "with a script that exits" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit
RUBY
end

it "logs and returns the correct exit status" do
allow($miq_ae_logger).to receive(:info).and_call_original
expect($miq_ae_logger).to receive(:info).with("Method exited with rc=MIQ_OK").at_least(:once)
expect($miq_ae_logger).to_not receive(:error)

expect(subject).to eq(0)
end
end

context "with a script that exits with an unknown return code" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit 1234
RUBY
end

it "does not log but raises an exception" do
expect($miq_ae_logger).to_not receive(:error)

expect { subject }.to raise_error(MiqAeException::UnknownMethodRc)
end
end

context "with a script that exits MIQ_OK" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit MIQ_OK
RUBY
end

it "logs and returns the correct exit status" do
allow($miq_ae_logger).to receive(:info).and_call_original
expect($miq_ae_logger).to receive(:info).with("Method exited with rc=MIQ_OK").at_least(:once)
expect($miq_ae_logger).to_not receive(:error)

expect(subject).to eq(0)
end
end

context "with a script that exits MIQ_WARN" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit MIQ_WARN
RUBY
end

it "logs and returns the correct exit status" do
allow($miq_ae_logger).to receive(:warn).and_call_original
expect($miq_ae_logger).to receive(:warn).with("Method exited with rc=MIQ_WARN").at_least(:once)
expect($miq_ae_logger).to_not receive(:error)

expect(subject).to eq(4)
end
end

context "with a script that exits MIQ_STOP" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit MIQ_STOP
RUBY
end

it "does not log but raises an exception" do
expect($miq_ae_logger).to_not receive(:error)

expect { subject }.to raise_error(MiqAeException::StopInstantiation)
end
end

context "with a script that exits MIQ_ABORT" do
let(:script) do
<<-RUBY
puts 'Hi from puts'
exit MIQ_ABORT
RUBY
end

it "does not log but raises an exception" do
expect($miq_ae_logger).to_not receive(:error)

expect { subject }.to raise_error(MiqAeException::AbortInstantiation)
end
end

context "with a script that does I/O" do
let(:script) do
<<-RUBY
Expand Down

0 comments on commit df20f49

Please sign in to comment.