Skip to content

Commit

Permalink
Add tests for Image create action
Browse files Browse the repository at this point in the history
  • Loading branch information
andyvesel committed Sep 26, 2017
1 parent b6ec06b commit 71f29b3
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
describe ManageIQ::Providers::Openstack::CloudManager::Template do
let(:ems) { FactoryGirl.create(:ems_openstack_with_authentication) }
let(:image_attributes) { {:name => "image", :ram => "1"} }
let(:template_openstack) { FactoryGirl.create :template_openstack, :ext_management_system => ems, :ems_ref => 'one_id' }
let(:service) { double }

context 'when create_image' do
before do
allow(ems).to receive(:with_provider_connection).with(:service => 'Image').and_yield(service)
end

context 'with correct data' do
it 'should create image' do
expect(service).to receive(:create_image).with(image_attributes).once
subject.class.create_image(ems, image_attributes)
end

it 'should not raise error' do
allow(service).to receive(:create_image).with(image_attributes).once
expect do
subject.class.create_image(ems, image_attributes)
end.not_to raise_error
end
end

context 'with incorrect data' do
[Excon::Error::BadRequest, ArgumentError].map do |error|
it "should raise error when #{error}" do
allow(service).to receive(:create_image).with(image_attributes).and_raise(error)
expect do
subject.class.create_image(ems, image_attributes)
end.to raise_error(MiqException::MiqOpenstackApiRequestError)
end
end
end
end
context 'when raw_delete_image' do
before do
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems)
Expand Down

0 comments on commit 71f29b3

Please sign in to comment.