From 02e866402a906811b7b2ce2f1804587259f102a7 Mon Sep 17 00:00:00 2001 From: Andrei Veselov Date: Fri, 8 Sep 2017 14:22:10 +0200 Subject: [PATCH] Add tests for Image create action --- .../openstack/cloud_manager/template_spec.rb | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 spec/models/manageiq/providers/openstack/cloud_manager/template_spec.rb diff --git a/spec/models/manageiq/providers/openstack/cloud_manager/template_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager/template_spec.rb new file mode 100644 index 000000000..734129ab4 --- /dev/null +++ b/spec/models/manageiq/providers/openstack/cloud_manager/template_spec.rb @@ -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