66 lines
2.5 KiB
Ruby
66 lines
2.5 KiB
Ruby
|
|
require 'db/mongo/models/deploy_env/deploy_env_ec2'
|
||
|
|
|
||
|
|
RSpec.describe Devops::Model::DeployEnvEc2, type: :model do
|
||
|
|
let(:env) { build(:deploy_env_ec2) }
|
||
|
|
|
||
|
|
before do
|
||
|
|
allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(ec2))
|
||
|
|
allow_any_instance_of(Validators::Helpers::Users).to receive(:available_users).and_return(['root'])
|
||
|
|
allow_any_instance_of(Validators::DeployEnv::Flavor).to receive(:available_flavors).and_return([{'id' => 'flavor'}])
|
||
|
|
allow_any_instance_of(Validators::FieldValidator::Flavor).to receive(:available_flavors).and_return([{'id' => 'flavor'}])
|
||
|
|
allow_any_instance_of(Validators::DeployEnv::Groups).to receive(:available_groups).and_return(['default'])
|
||
|
|
allow_any_instance_of(Validators::DeployEnv::Image).to receive(:available_images).and_return([{'id' => 'image'}])
|
||
|
|
allow_any_instance_of(Validators::DeployEnv::Image).to receive(:available_images).and_return([{'id' => 'image'}])
|
||
|
|
allow_any_instance_of(Validators::DeployEnv::StackTemplate).to receive(:available_stack_templates).and_return([{'id' => 'template'}])
|
||
|
|
allow_any_instance_of(Validators::FieldValidator::Image).to receive(:available_images).and_return([{'id' => 'image'}])
|
||
|
|
end
|
||
|
|
|
||
|
|
it_behaves_like 'deploy env'
|
||
|
|
it_behaves_like 'cloud deploy env'
|
||
|
|
|
||
|
|
describe '#initialize' do
|
||
|
|
it 'keep only first subnet in given array' do
|
||
|
|
env = described_class.new('subnets' => %w(foo bar))
|
||
|
|
expect(env.subnets).to match_array(%w(foo))
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#to_hash' do
|
||
|
|
it 'includes vpc_id' do
|
||
|
|
expect(env.to_hash).to include('vpc_id')
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '.create' do
|
||
|
|
it 'returns instance of DeployEnvEc2' do
|
||
|
|
expect(described_class.create({})).to be_an_instance_of(described_class)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#subnets_filter' do
|
||
|
|
before do
|
||
|
|
allow_any_instance_of(described_class).to receive_message_chain('provider_instance.networks') {
|
||
|
|
[{'name' => 'foo', 'vpcId' => 'bar'}]
|
||
|
|
}
|
||
|
|
end
|
||
|
|
|
||
|
|
it 'returns nil if #subnets are empty' do
|
||
|
|
expect(build(:deploy_env_ec2, subnets: []).subnets_filter).to be_nil
|
||
|
|
end
|
||
|
|
|
||
|
|
context "when provider has env's network" do
|
||
|
|
it 'returns hash with vpcId of that network' do
|
||
|
|
env = build(:deploy_env_ec2, subnets: ['foo'])
|
||
|
|
expect(env.subnets_filter).to eq({'vpc-id' => 'bar'})
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
context "when provider hasn't env's network" do
|
||
|
|
it 'returns nil' do
|
||
|
|
env = build(:deploy_env_ec2, subnets: ['wrong'])
|
||
|
|
expect(env.subnets_filter).to be nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|