62 lines
1.9 KiB
Ruby
62 lines
1.9 KiB
Ruby
require 'db/mongo/models/stack_template/stack_template_ec2'
|
|
require_relative 'shared_stack_template_specs'
|
|
|
|
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))
|
|
provider_double = instance_double('Provider::Ec2',
|
|
validate_stack_template: true,
|
|
store_stack_template: {'url' => 'template_url'}
|
|
)
|
|
allow(Provider::ProviderFactory).to receive(:get) { provider_double }
|
|
end
|
|
|
|
it_behaves_like 'stack template'
|
|
|
|
it 'uploads file to S3' do
|
|
result = described_class.create('id' => 'foo',
|
|
'template_body' => '{}',
|
|
'owner' => 'root',
|
|
'provider' => 'ec2'
|
|
)
|
|
expect(result).to be_an_instance_of(described_class)
|
|
expect(result.template_url).to eq 'template_url'
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
|
end |