Skip to content

Commit

Permalink
Add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed May 21, 2018
1 parent 3faa52c commit e088606
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/models/miq_provision/state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,29 @@
template.reload.with_relationship_type("genealogy") { |v| expect(v.children).to eq([vm]) }
end
end

context "#log_last_worker" do
let(:server) { FactoryGirl.create(:miq_server, :name => "test_server", :zone => FactoryGirl.create(:zone)) }
let(:worker) { FactoryGirl.create(:miq_worker, :miq_server => server) }

it "logs worker/server info with last_worker_id in phase_context" do
task.update_attributes(:phase_context => {:last_worker_id => worker.id})
expect($log).to receive(:info).with(/Task was previously processed by Worker id:.*Server id/)
task.log_last_worker
end

it "logs worker id with worker does not exist" do
task.update_attributes(:phase_context => {:last_worker_id => worker.id})
expect($log).to receive(:info).with(/Task was previously processed by Worker id:.*which does not exist any more/)
worker.delete
task.log_last_worker
end

it "doesn't write a message if no last_worker_id in phase_context" do
expect(MiqWorker).not_to receive(:find_by)
expect($log).not_to receive(:info).with(/Task was previously processed by Worker id:/)
task.log_last_worker
end
end
end
end

0 comments on commit e088606

Please sign in to comment.