awspec 0.21.2 → 0.21.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/resource_types.md +2 -0
- data/lib/awspec/command/generate.rb +1 -1
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/spec/route_table.rb +26 -2
- data/lib/awspec/generator/spec/subnet.rb +47 -0
- data/lib/awspec/helper/finder/vpc.rb +7 -0
- data/lib/awspec/stub/route_table.rb +24 -0
- data/lib/awspec/type/route_table.rb +8 -0
- data/lib/awspec/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e1afe8cf22c31470696adebc9e12ade123b1c38
|
4
|
+
data.tar.gz: 092d0c2c0f93889e78c967f4cc9c8cee58193958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64a0e66d01174810da25ca200eb23ab2077dfc4ca1daa34fee6649ae62156cdf57665a60959bcdd27373f53118691576d02a59646a4f297adf6214689b8d3c5
|
7
|
+
data.tar.gz: a465fbb92cdea043fac44eca48f1588f677d45ecc815607709cd2fda59281a9c80aaf810f8d13f0210a8884acfc9be1bbdaf73f42311b5717b8e091131a2a847
|
data/doc/resource_types.md
CHANGED
data/lib/awspec/generator.rb
CHANGED
@@ -11,6 +11,7 @@ require 'awspec/generator/spec/iam_policy'
|
|
11
11
|
require 'awspec/generator/spec/cloudwatch_alarm'
|
12
12
|
require 'awspec/generator/spec/network_acl'
|
13
13
|
require 'awspec/generator/spec/route_table'
|
14
|
+
require 'awspec/generator/spec/subnet'
|
14
15
|
|
15
16
|
# Doc
|
16
17
|
require 'awspec/generator/doc/type'
|
@@ -11,7 +11,8 @@ module Awspec::Generator
|
|
11
11
|
@vpc_tag_name = vpc.tag_name
|
12
12
|
route_tables = select_route_table_by_vpc_id(@vpc_id)
|
13
13
|
specs = route_tables.map do |route_table|
|
14
|
-
linespecs =
|
14
|
+
linespecs = generate_route_linespecs(route_table)
|
15
|
+
subnet_linespecs = generate_subnet_linespecs(route_table)
|
15
16
|
route_table_id = route_table[:route_table_id]
|
16
17
|
route_table_tag_name = route_table.tag_name
|
17
18
|
content = ERB.new(route_table_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
@@ -19,7 +20,7 @@ module Awspec::Generator
|
|
19
20
|
specs.join("\n")
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
+
def generate_route_linespecs(route_table)
|
23
24
|
linespecs = []
|
24
25
|
route_table.routes.each do |route|
|
25
26
|
linespecs.push(ERB.new(route_table_spec_gateway_linetemplate, nil, '-').result(binding)) if route.gateway_id
|
@@ -31,6 +32,15 @@ module Awspec::Generator
|
|
31
32
|
linespecs
|
32
33
|
end
|
33
34
|
|
35
|
+
def generate_subnet_linespecs(route_table)
|
36
|
+
linespecs = []
|
37
|
+
route_table.associations.each do |a|
|
38
|
+
subnet = find_subnet(a.subnet_id)
|
39
|
+
linespecs.push(ERB.new(route_table_spec_subnet_linetemplate, nil, '-').result(binding)) if subnet
|
40
|
+
end
|
41
|
+
linespecs
|
42
|
+
end
|
43
|
+
|
34
44
|
def route_table_spec_gateway_linetemplate
|
35
45
|
template = <<-'EOF'
|
36
46
|
it { should have_route('<%= route.destination_cidr_block %>').target(gateway: '<%= route.gateway_id %>') }
|
@@ -49,6 +59,17 @@ EOF
|
|
49
59
|
template
|
50
60
|
end
|
51
61
|
|
62
|
+
def route_table_spec_subnet_linetemplate
|
63
|
+
template = <<-'EOF'
|
64
|
+
<%- if subnet.tag_name -%>
|
65
|
+
it { should have_subnet('<%= subnet.tag_name %>') }
|
66
|
+
<%- else -%>
|
67
|
+
it { should have_subnet('<%= subnet.subnet_id %>') }
|
68
|
+
<%- end -%>
|
69
|
+
EOF
|
70
|
+
template
|
71
|
+
end
|
72
|
+
|
52
73
|
def route_table_spec_template
|
53
74
|
template = <<-'EOF'
|
54
75
|
<%- if route_table_tag_name -%>
|
@@ -65,6 +86,9 @@ describe route_table('<%= route_table_id %>') do
|
|
65
86
|
<% linespecs.each do |line| %>
|
66
87
|
<%= line %>
|
67
88
|
<% end %>
|
89
|
+
<% subnet_linespecs.each do |line| %>
|
90
|
+
<%= line %>
|
91
|
+
<% end %>
|
68
92
|
end
|
69
93
|
EOF
|
70
94
|
template
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class Subnet
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_by_vpc_id(vpc_id)
|
6
|
+
describes = %w(
|
7
|
+
subnet_id cidr_block
|
8
|
+
)
|
9
|
+
vpc = find_vpc(vpc_id)
|
10
|
+
fail 'Not Found VPC' unless vpc
|
11
|
+
@vpc_id = vpc[:vpc_id]
|
12
|
+
@vpc_tag_name = vpc.tag_name
|
13
|
+
subnets = select_subnet_by_vpc_id(@vpc_id)
|
14
|
+
specs = subnets.map do |subnet|
|
15
|
+
subnet_id = subnet[:subnet_id]
|
16
|
+
subnet_tag_name = subnet.tag_name
|
17
|
+
content = ERB.new(subnet_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
18
|
+
end
|
19
|
+
specs.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
def subnet_spec_template
|
23
|
+
template = <<-'EOF'
|
24
|
+
<%- if subnet_tag_name -%>
|
25
|
+
describe subnet('<%= subnet_tag_name %>') do
|
26
|
+
<%- else -%>
|
27
|
+
describe subnet('<%= subnet_id %>') do
|
28
|
+
<%- end -%>
|
29
|
+
it { should exist }
|
30
|
+
it { should be_<%= subnet.state %> }
|
31
|
+
it { should belong_to_vpc('<%= @vpc_tag_name %>') }
|
32
|
+
<% describes.each do |describe| %>
|
33
|
+
<%- if subnet.members.include?(describe.to_sym) && !subnet[describe.to_sym].nil? -%>
|
34
|
+
<%- if subnet[describe].is_a?(String) -%>
|
35
|
+
its(:<%= describe %>) { should eq '<%= subnet[describe] %>' }
|
36
|
+
<%- else -%>
|
37
|
+
its(:<%= describe %>) { should eq <%= subnet[describe] %> }
|
38
|
+
<%- end -%>
|
39
|
+
<%- end -%>
|
40
|
+
<% end %>
|
41
|
+
end
|
42
|
+
EOF
|
43
|
+
template
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -58,6 +58,13 @@ module Awspec::Helper
|
|
58
58
|
})
|
59
59
|
return res[:subnets].first if res[:subnets].count == 1
|
60
60
|
end
|
61
|
+
|
62
|
+
def select_subnet_by_vpc_id(vpc_id)
|
63
|
+
res = @ec2_client.describe_subnets({
|
64
|
+
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
65
|
+
})
|
66
|
+
res[:subnets]
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
@@ -92,6 +92,14 @@ Aws.config[:ec2] = {
|
|
92
92
|
state: 'active'
|
93
93
|
}
|
94
94
|
],
|
95
|
+
associations: [
|
96
|
+
{
|
97
|
+
route_table_association_id: 'rtbassoc-b123456cd',
|
98
|
+
route_table_id: 'rtb-a12bcd34',
|
99
|
+
subnet_id: 'subnet-1234a567',
|
100
|
+
main: false
|
101
|
+
}
|
102
|
+
],
|
95
103
|
tags: [
|
96
104
|
{
|
97
105
|
key: 'Name',
|
@@ -101,6 +109,22 @@ Aws.config[:ec2] = {
|
|
101
109
|
}
|
102
110
|
]
|
103
111
|
},
|
112
|
+
describe_subnets: {
|
113
|
+
subnets: [
|
114
|
+
{
|
115
|
+
state: 'available',
|
116
|
+
vpc_id: 'vpc-ab123cde',
|
117
|
+
subnet_id: 'subnet-1234a567',
|
118
|
+
cidr_block: '10.0.1.0/24',
|
119
|
+
tags: [
|
120
|
+
{
|
121
|
+
key: 'Name',
|
122
|
+
value: 'my-subnet'
|
123
|
+
}
|
124
|
+
]
|
125
|
+
}
|
126
|
+
]
|
127
|
+
},
|
104
128
|
describe_internet_gateways: {
|
105
129
|
internet_gateways: [
|
106
130
|
{
|
@@ -28,5 +28,13 @@ module Awspec::Type
|
|
28
28
|
next true if instance && instance.tag_name == instance_id
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
def has_subnet?(subnet_id)
|
33
|
+
subnet = find_subnet(subnet_id)
|
34
|
+
return false unless subnet
|
35
|
+
@resource.associations.find do |a|
|
36
|
+
a[:subnet_id] == subnet[:subnet_id]
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
data/lib/awspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.
|
4
|
+
version: 0.21.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- lib/awspec/generator/spec/route53_hosted_zone.rb
|
237
237
|
- lib/awspec/generator/spec/route_table.rb
|
238
238
|
- lib/awspec/generator/spec/security_group.rb
|
239
|
+
- lib/awspec/generator/spec/subnet.rb
|
239
240
|
- lib/awspec/generator/spec/vpc.rb
|
240
241
|
- lib/awspec/generator/template.rb
|
241
242
|
- lib/awspec/helper.rb
|