| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | require 'db/mongo/models/stack_template/stack_template_ec2' | 
					
						
							| 
									
										
										
										
											2015-12-10 01:24:23 +03:00
										 |  |  | require_relative 'shared_stack_template_specs' | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | RSpec.describe Devops::Model::StackTemplateEc2, type: :model do | 
					
						
							|  |  |  |   let(:stack_template) { build(:stack_template_ec2) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   before do | 
					
						
							|  |  |  |     allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(ec2)) | 
					
						
							| 
									
										
										
										
											2016-01-28 14:54:12 +03:00
										 |  |  |     provider_double = instance_double('Provider::Ec2', | 
					
						
							|  |  |  |       validate_stack_template: true, | 
					
						
							|  |  |  |       store_stack_template: {'url' => 'template_url'} | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     allow(Provider::ProviderFactory).to receive(:get) { provider_double } | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it_behaves_like 'stack template' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:37:45 +03:00
										 |  |  |   it 'uploads file to S3' do | 
					
						
							| 
									
										
										
										
											2016-01-28 14:54:12 +03:00
										 |  |  |     result = described_class.create('id' => 'foo', | 
					
						
							| 
									
										
										
										
											2016-01-27 11:37:45 +03:00
										 |  |  |       'template_body' => '{}', | 
					
						
							|  |  |  |       'owner' => 'root', | 
					
						
							|  |  |  |       'provider' => 'ec2' | 
					
						
							| 
									
										
										
										
											2016-01-28 14:54:12 +03:00
										 |  |  |     ) | 
					
						
							|  |  |  |     expect(result).to be_an_instance_of(described_class) | 
					
						
							|  |  |  |     expect(result.template_url).to eq 'template_url' | 
					
						
							| 
									
										
										
										
											2016-01-27 11:37:45 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-28 18:15:06 +03:00
										 |  |  |   describe 'available parameters fetching' do | 
					
						
							|  |  |  |     let(:template_body) { %q(
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           "Description" : "Example", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           "Parameters" : { | 
					
						
							|  |  |  |             "KeyName": { | 
					
						
							|  |  |  |               "Description" : "Name of KeyPair", | 
					
						
							|  |  |  |               "Type": "AWS::EC2::KeyPair::KeyName" | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |            "SSHLocation" : { | 
					
						
							|  |  |  |               "Type": "String", | 
					
						
							|  |  |  |               "MinLength": "9" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ) } | 
					
						
							|  |  |  |     let(:template_attributes) { FactoryGirl.attributes_for(:stack_template_ec2, template_body: template_body) } | 
					
						
							|  |  |  |     let(:template) { described_class.create(template_attributes.stringify_keys) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it 'fetches parameters from template body' do | 
					
						
							|  |  |  |       expect(template.available_parameters).to be_a(Hash) | 
					
						
							|  |  |  |       expect(template.available_parameters).to include('KeyName', 'SSHLocation') | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it 'parses description' do | 
					
						
							|  |  |  |       expect(template.available_parameters['KeyName']['description']).to eq 'Name of KeyPair' | 
					
						
							|  |  |  |       expect(template.available_parameters['SSHLocation']['description']).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | end |