Sha256: 7d4b58a4a972b2c32d6a62e6718eee8022b1b14d9da9044d5b543508288e5c54
Contents?: true
Size: 1.32 KB
Versions: 12
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true module Awspec::Generator module Spec class Subnet include Awspec::Helper::Finder def generate_by_vpc_id(vpc_id) describes = %w[ subnet_id cidr_block ] vpc = find_vpc(vpc_id) raise 'Not Found VPC' unless vpc @vpc_id = vpc[:vpc_id] @vpc_tag_name = vpc.tag_name subnets = select_subnet_by_vpc_id(@vpc_id) specs = subnets.map do |subnet| subnet_id = subnet[:subnet_id] subnet_tag_name = subnet.tag_name content = ERB.new(subnet_spec_template, nil, '-').result(binding).gsub(/^\n/, '') end specs.join("\n") end def subnet_spec_template <<-'EOF' <%- if subnet_tag_name -%> describe subnet('<%= subnet_tag_name %>') do <%- else -%> describe subnet('<%= subnet_id %>') do <%- end -%> it { should exist } it { should be_<%= subnet.state %> } it { should belong_to_vpc('<%= @vpc_tag_name %>') } <% describes.each do |describe| %> <%- if subnet.members.include?(describe.to_sym) && !subnet[describe.to_sym].nil? -%> <%- if subnet[describe].is_a?(String) -%> its(:<%= describe %>) { should eq '<%= subnet[describe] %>' } <%- else -%> its(:<%= describe %>) { should eq <%= subnet[describe] %> } <%- end -%> <%- end -%> <% end %> end EOF end end end end
Version data entries
12 entries across 12 versions & 1 rubygems