-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from k1LoW/add-type-directconnect_virtual_inte…
…rface Add directconnect_virtual_interface type
- Loading branch information
Showing
13 changed files
with
178 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
lib/awspec/generator/doc/type/directconnect_virtual_interface.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Awspec::Generator | ||
module Doc | ||
module Type | ||
class DirectconnectVirtualInterface < Base | ||
def initialize | ||
super | ||
@type_name = 'DirectconnectVirtualInterface' | ||
@type = Awspec::Type::DirectconnectVirtualInterface.new('my-directconnect-virtual-interface') | ||
@ret = @type.resource | ||
@matchers = [] | ||
@ignore_matchers = [] | ||
@describes = [] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Awspec::Generator | ||
module Spec | ||
class Directconnect | ||
include Awspec::Helper::Finder | ||
def generate_all | ||
generate_virtual_interface_all | ||
end | ||
|
||
def generate_virtual_interface_all | ||
virtual_interfaces = select_virtual_interfaces | ||
virtual_interfaces.empty? && fail('Not Found virtual_interfaces') | ||
ERB.new(virtual_interface_spec_template, nil, '-').result(binding).chomp | ||
end | ||
|
||
def virtual_interface_spec_template | ||
template = <<-'EOF' | ||
<% virtual_interfaces.each do |interface| %> | ||
describe directconnect_virtual_interface('<%= interface.virtual_interface_name %>') do | ||
it { should exist } | ||
it { should be_<%= interface.virtual_interface_state %> } | ||
its(:connection_id) { should eq '<%= interface.connection_id %>' } | ||
its(:virtual_interface_id) { should eq '<%= interface.virtual_interface_id %>' } | ||
its(:amazon_address) { should eq '<%= interface.amazon_address %>' } | ||
its(:customer_address) { should eq '<%= interface.customer_address %>' } | ||
its(:virtual_gateway_id) { should eq '<%= interface.virtual_gateway_id %>' } | ||
end | ||
<% end %> | ||
EOF | ||
template | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Awspec::Helper | ||
module Finder | ||
module Directconnect | ||
def find_virtual_interface(virtual_interface_id) | ||
res = @directconnect_client.describe_virtual_interfaces | ||
ret = res.virtual_interfaces.select do |virtual_interface| | ||
next true if virtual_interface.virtual_interface_id == virtual_interface_id | ||
next true if virtual_interface.virtual_interface_name == virtual_interface_id | ||
end | ||
return ret.first if ret.count == 1 | ||
end | ||
|
||
def select_virtual_interfaces | ||
res = @directconnect_client.describe_virtual_interfaces | ||
res.virtual_interfaces | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Aws.config[:directconnect] = { | ||
stub_responses: { | ||
describe_virtual_interfaces: { | ||
virtual_interfaces: [ | ||
{ | ||
owner_account: '123456789012', | ||
virtual_interface_id: 'dxvif-aabbccdd', | ||
location: 'AbCD5', | ||
connection_id: 'dxcon-abcd5fgh', | ||
virtual_interface_type: 'private', | ||
virtual_interface_name: 'my-directconnect-virtual-interface', | ||
vlan: 400, | ||
asn: 65_007, | ||
auth_key: nil, | ||
amazon_address: '170.252.252.1/30', | ||
customer_address: '123.456.789.2/30', | ||
virtual_interface_state: 'available', | ||
customer_router_config: nil, | ||
virtual_gateway_id: 'vgw-d234e5f6', | ||
route_filter_prefixes: [] | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Awspec::Type | ||
class DirectconnectVirtualInterface < Base | ||
def initialize(id) | ||
super | ||
@resource = find_virtual_interface(id) | ||
@id = @resource[:virtual_interface_id] if @resource | ||
end | ||
|
||
states = %w( | ||
confirming verifying pending available | ||
deleting deleted rejected | ||
) | ||
|
||
states.each do |state| | ||
define_method state + '?' do | ||
@resource[:virtual_interface_state] == state | ||
end | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
spec/generator/spec/directconnect_virtual_interface_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Awspec::Generator::Spec::Directconnect' do | ||
before do | ||
Awspec::Stub.load 'directconnect_virtual_interface' | ||
end | ||
let(:directconnect) { Awspec::Generator::Spec::Directconnect.new } | ||
it 'generate_by_vpc_id generate spec' do | ||
spec = <<-'EOF' | ||
describe directconnect_virtual_interface('my-directconnect-virtual-interface') do | ||
it { should exist } | ||
it { should be_available } | ||
its(:connection_id) { should eq 'dxcon-abcd5fgh' } | ||
its(:virtual_interface_id) { should eq 'dxvif-aabbccdd' } | ||
its(:amazon_address) { should eq '170.252.252.1/30' } | ||
its(:customer_address) { should eq '123.456.789.2/30' } | ||
its(:virtual_gateway_id) { should eq 'vgw-d234e5f6' } | ||
end | ||
EOF | ||
expect(directconnect.generate_all.to_s.gsub(/\n/, "\n")).to eq spec | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
Awspec::Stub.load 'directconnect_virtual_interface' | ||
|
||
describe directconnect_virtual_interface('my-directconnect-virtual-interface') do | ||
it { should exist } | ||
it { should be_available } | ||
its(:connection_id) { should eq 'dxcon-abcd5fgh' } | ||
its(:virtual_interface_id) { should eq 'dxvif-aabbccdd' } | ||
its(:amazon_address) { should eq '170.252.252.1/30' } | ||
its(:customer_address) { should eq '123.456.789.2/30' } | ||
its(:virtual_gateway_id) { should eq 'vgw-d234e5f6' } | ||
end |