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))
|
|
|
|
|
allow_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.validate_stack_template') { true }
|
2016-01-27 11:37:45 +03:00
|
|
|
allow_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.store_stack_template') { {'url' => nil} }
|
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
|
|
|
|
|
expect_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.store_stack_template')
|
|
|
|
|
params = {
|
|
|
|
|
'id' => 'foo',
|
|
|
|
|
'template_body' => '{}',
|
|
|
|
|
'owner' => 'root',
|
|
|
|
|
'provider' => 'ec2'
|
|
|
|
|
}
|
|
|
|
|
expect(described_class.create(params)).to be_an_instance_of(described_class)
|
|
|
|
|
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
|