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 8, 2017
1 parent 4db1236 commit 02e8664
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 }
let(:service) { double }

context 'when raw_create_image' do
before do
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems)
allow(ems).to receive(:with_provider_connection).with(:service => 'Compute').and_yield(service)
allow(service).to receive(:images).and_return(images)
end

let(:images) { double }

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

it 'should not raise error' do
allow(images).to receive(:create).with(image_attributes).and_return(template_openstack).once
expect do
subject.class.raw_create_image(ems, image_attributes)
end.not_to raise_error
end
end

context 'with incorrect data' do
let(:image_attributes) { { :ram => "1"} }
[Excon::Error::BadRequest, ArgumentError].map do |error|
it "should raise error when #{error.to_s}" do
allow(images).to receive(:create).with(image_attributes).and_raise(error)
expect do
subject.class.raw_create_image(ems, image_attributes)
end.to raise_error(MiqException::MiqOpenstackApiRequestError)
end
end
end
end
end

0 comments on commit 02e8664

Please sign in to comment.