Sha256: 49726003eb3323c80a01b8531aa05ecc9ff3d6f52cd83e95cba23e7f16fc1ad7

Contents?: true

Size: 1.58 KB

Versions: 55

Compression:

Stored size: 1.58 KB

Contents

module Awspec::Generator
  module Spec
    class Vpc
      include Awspec::Helper::Finder
      def generate_by_vpc_id(vpc_id)
        describes = %w(
          vpc_id cidr_block
        )
        vpc = find_vpc(vpc_id)
        fail 'Not Found VPC' unless vpc
        @vpc_id = vpc[:vpc_id]
        @vpc_tag_name = vpc.tag_name
        route_tables = select_route_table_by_vpc_id(@vpc_id)
        network_acls = select_network_acl_by_vpc_id(@vpc_id)
        spec = ERB.new(vpc_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
      end

      # rubocop:disable all
      def vpc_spec_template
        template = <<-'EOF'
<%- if @vpc_tag_name -%>
describe vpc('<%= @vpc_tag_name %>') do
<%- else -%>
describe vpc('<%= @vpc_id %>') do
<%- end -%>
  it { should exist }
  it { should be_<%= vpc.state %> }
<% describes.each do |describe| %>
<%- if vpc.key?(describe) -%>
<%- if vpc[describe].is_a?(String) -%>
  its(:<%= describe %>) { should eq '<%= vpc[describe] %>' }
<%- else -%>
  its(:<%= describe %>) { should eq <%= vpc[describe] %> }
<%- end -%>
<%- end -%>
<% end %>
<% route_tables.each do |route_table| %>
<%- if route_table.tag_name -%>
  it { should have_route_table('<%= route_table.tag_name %>') }
<%- else -%>
  it { should have_route_table('<%= route_table.route_table_id %>') }
<%- end -%>
<% end %>
<% network_acls.each do |network_acl| %>
<%- if network_acl.tag_name -%>
  it { should have_network_acl('<%= network_acl.tag_name %>') }
<%- else -%>
  it { should have_network_acl('<%= network_acl.network_acl_id %>') }
<%- end -%>
<% end %>
end
EOF
        template
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
awspec-0.13.0 lib/awspec/generator/spec/vpc.rb
awspec-0.12.1 lib/awspec/generator/spec/vpc.rb
awspec-0.12.0 lib/awspec/generator/spec/vpc.rb
awspec-0.11.0 lib/awspec/generator/spec/vpc.rb
awspec-0.10.2 lib/awspec/generator/spec/vpc.rb
awspec-0.10.1 lib/awspec/generator/spec/vpc.rb
awspec-0.10.0 lib/awspec/generator/spec/vpc.rb
awspec-0.9.0 lib/awspec/generator/spec/vpc.rb
awspec-0.8.1 lib/awspec/generator/spec/vpc.rb
awspec-0.8.0 lib/awspec/generator/spec/vpc.rb
awspec-0.7.0 lib/awspec/generator/spec/vpc.rb
awspec-0.6.4 lib/awspec/generator/spec/vpc.rb
awspec-0.6.3 lib/awspec/generator/spec/vpc.rb
awspec-0.6.2 lib/awspec/generator/spec/vpc.rb
awspec-0.6.1 lib/awspec/generator/spec/vpc.rb