-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
spec/models/manageiq/providers/openstack/cloud_manager/template_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |