geoengineer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +5 -0
- data.tar.gz.sig +0 -0
- data/README.md +5 -5
- data/lib/geoengineer/cli/geo_cli.rb +4 -5
- data/lib/geoengineer/cli/status_command.rb +7 -1
- data/lib/geoengineer/environment.rb +53 -51
- data/lib/geoengineer/project.rb +5 -24
- data/lib/geoengineer/resource.rb +89 -20
- data/lib/geoengineer/resources/aws_customer_gateway.rb +23 -0
- data/lib/geoengineer/resources/aws_eip.rb +43 -0
- data/lib/geoengineer/resources/aws_iam_group.rb +26 -0
- data/lib/geoengineer/resources/aws_iam_group_membership.rb +50 -0
- data/lib/geoengineer/resources/aws_iam_policy.rb +12 -4
- data/lib/geoengineer/resources/aws_iam_policy_attachment.rb +95 -0
- data/lib/geoengineer/resources/aws_iam_role.rb +45 -0
- data/lib/geoengineer/resources/aws_instance.rb +7 -4
- data/lib/geoengineer/resources/aws_internet_gateway.rb +23 -0
- data/lib/geoengineer/resources/aws_lambda_alias.rb +50 -0
- data/lib/geoengineer/resources/aws_lambda_event_source_mapping.rb +47 -0
- data/lib/geoengineer/resources/aws_lambda_function.rb +30 -0
- data/lib/geoengineer/resources/aws_lambda_permission.rb +74 -0
- data/lib/geoengineer/resources/aws_main_route_table_association.rb +51 -0
- data/lib/geoengineer/resources/aws_nat_gateway.rb +29 -0
- data/lib/geoengineer/resources/aws_network_acl.rb +38 -0
- data/lib/geoengineer/resources/aws_network_acl_rule.rb +50 -0
- data/lib/geoengineer/resources/aws_route.rb +47 -0
- data/lib/geoengineer/resources/aws_route53_record.rb +4 -0
- data/lib/geoengineer/resources/aws_route_table.rb +26 -0
- data/lib/geoengineer/resources/aws_route_table_association.rb +45 -0
- data/lib/geoengineer/resources/aws_security_group.rb +8 -5
- data/lib/geoengineer/resources/aws_subnet.rb +24 -0
- data/lib/geoengineer/resources/aws_vpc.rb +24 -0
- data/lib/geoengineer/resources/aws_vpc_dhcp_options.rb +29 -0
- data/lib/geoengineer/resources/aws_vpc_dhcp_options_association.rb +40 -0
- data/lib/geoengineer/resources/aws_vpc_endpoint.rb +26 -0
- data/lib/geoengineer/resources/aws_vpc_peering_connection.rb +29 -0
- data/lib/geoengineer/resources/aws_vpn_connection.rb +23 -0
- data/lib/geoengineer/resources/aws_vpn_connection_route.rb +35 -0
- data/lib/geoengineer/resources/aws_vpn_gateway.rb +22 -0
- data/lib/geoengineer/resources/aws_vpn_gateway_attachment.rb +41 -0
- data/lib/geoengineer/template.rb +20 -4
- data/lib/geoengineer/utils/aws_clients.rb +4 -0
- data/lib/geoengineer/utils/crc32.rb +61 -0
- data/lib/geoengineer/utils/has_attributes.rb +25 -11
- data/lib/geoengineer/utils/has_projects.rb +21 -0
- data/lib/geoengineer/utils/has_resources.rb +17 -4
- data/lib/geoengineer/utils/has_templates.rb +31 -0
- data/lib/geoengineer/utils/has_validations.rb +18 -3
- data/lib/geoengineer/version.rb +1 -1
- data/spec/environment_spec.rb +40 -19
- data/spec/project_spec.rb +2 -2
- data/spec/resource_spec.rb +87 -6
- data/spec/resources/aws_customer_gateway_spec.rb +24 -0
- data/spec/resources/aws_eip_spec.rb +29 -0
- data/spec/resources/aws_iam_group_membership_spec.rb +83 -0
- data/spec/resources/aws_iam_group_spec.rb +43 -0
- data/spec/resources/aws_iam_policy_attachment_spec.rb +80 -0
- data/spec/resources/{aws_iam_policy.rb → aws_iam_policy_spec.rb} +6 -5
- data/spec/resources/aws_iam_role_spec.rb +45 -0
- data/spec/resources/aws_internet_gateway_spec.rb +24 -0
- data/spec/resources/aws_lambda_alias_spec.rb +39 -0
- data/spec/resources/aws_lambda_event_source_mapping_spec.rb +53 -0
- data/spec/resources/aws_lambda_function_spec.rb +29 -0
- data/spec/resources/aws_lambda_permission_spec.rb +90 -0
- data/spec/resources/aws_main_route_table_association_spec.rb +57 -0
- data/spec/resources/aws_nat_gateway_spec.rb +31 -0
- data/spec/resources/aws_network_acl_rule_spec.rb +73 -0
- data/spec/resources/aws_network_acl_spec.rb +31 -0
- data/spec/resources/aws_route53_record_spec.rb +5 -0
- data/spec/resources/aws_route_spec.rb +47 -0
- data/spec/resources/aws_route_table_association_spec.rb +47 -0
- data/spec/resources/aws_route_table_spec.rb +24 -0
- data/spec/resources/aws_security_group_spec.rb +36 -2
- data/spec/resources/aws_subnet_spec.rb +24 -0
- data/spec/resources/aws_vpc_dhcp_options_association_spec.rb +43 -0
- data/spec/resources/aws_vpc_dhcp_options_spec.rb +24 -0
- data/spec/resources/aws_vpc_endpoint_spec.rb +41 -0
- data/spec/resources/aws_vpc_peering_connection_spec.rb +33 -0
- data/spec/resources/aws_vpc_spec.rb +24 -0
- data/spec/resources/aws_vpn_connection_route_spec.rb +43 -0
- data/spec/resources/aws_vpn_connection_spec.rb +41 -0
- data/spec/resources/aws_vpn_gateway_attachment_spec.rb +41 -0
- data/spec/resources/aws_vpn_gateway_spec.rb +39 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/utils/crc32_spec.rb +14 -0
- data/spec/utils/has_attributes_spec.rb +22 -0
- data/spec/utils/has_resources_spec.rb +4 -0
- data/spec/utils/has_validations_spec.rb +45 -0
- metadata +117 -6
- metadata.gz.sig +1 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "GeoEngineer::Resource::AwsIamGroup" do
|
4
|
+
common_resource_tests(GeoEngineer::Resources::AwsIamGroup, 'aws_iam_group')
|
5
|
+
|
6
|
+
let(:aws_client) { AwsClients.iam }
|
7
|
+
|
8
|
+
before { aws_client.setup_stubbing }
|
9
|
+
|
10
|
+
describe '#_fetch_remote_resources' do
|
11
|
+
before do
|
12
|
+
aws_client.stub_responses(
|
13
|
+
:list_groups, {
|
14
|
+
groups: [
|
15
|
+
{
|
16
|
+
group_name: "Some-IAM-Group",
|
17
|
+
group_id: "AAAAAAAAAAAAAAAAAAAAA",
|
18
|
+
path: "/",
|
19
|
+
arn: "arn:aws:iam::000000000000:group/Some-IAM-Group",
|
20
|
+
create_date: Time.parse('2014-12-01T00:00:00Z')
|
21
|
+
},
|
22
|
+
{
|
23
|
+
group_name: "Another-IAM-group",
|
24
|
+
group_id: "AAAAAAAAAAAAAAAAAAAAA",
|
25
|
+
path: "/",
|
26
|
+
arn: "arn:aws:iam::000000000000:group/Another-IAM-group",
|
27
|
+
create_date: Time.parse('2014-12-01T00:00:00Z')
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create a list of hashes returned AWS SDK' do
|
35
|
+
resources = GeoEngineer::Resources::AwsIamGroup._fetch_remote_resources
|
36
|
+
expect(resources.count).to eql(2)
|
37
|
+
|
38
|
+
test_iam_group = resources.first
|
39
|
+
expect(test_iam_group[:_terraform_id]).to eql("Some-IAM-Group")
|
40
|
+
expect(test_iam_group[:_geo_id]).to eql("Some-IAM-Group")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "GeoEngineer::Resources::AwsIamPolicy" do
|
4
|
+
let(:aws_client) { AwsClients.iam }
|
5
|
+
|
6
|
+
let(:iam_policy) do
|
7
|
+
GeoEngineer::Resources::AwsIamPolicy.new('aws_iam_policy', 'fake_policy') {
|
8
|
+
name 'Fake-Aws-Policy'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:iam_policy_attachment) do
|
13
|
+
policy = iam_policy
|
14
|
+
|
15
|
+
GeoEngineer::Resources::AwsIamPolicyAttachment
|
16
|
+
.new('aws_iam_policy_attachment', 'fake_policy_attachment') {
|
17
|
+
_policy policy
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
common_resource_tests(
|
22
|
+
GeoEngineer::Resources::AwsIamPolicyAttachment,
|
23
|
+
'aws_iam_policy_attachment',
|
24
|
+
false
|
25
|
+
)
|
26
|
+
|
27
|
+
describe '#remote_resource' do
|
28
|
+
before do
|
29
|
+
aws_client.stub_responses(
|
30
|
+
:list_policies,
|
31
|
+
{
|
32
|
+
policies: [
|
33
|
+
{
|
34
|
+
arn: 'arn:aws:iam::aws:policy/xyv/FakeAwsARN',
|
35
|
+
policy_name: 'Fake-Aws-Policy'
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
)
|
40
|
+
|
41
|
+
aws_client.stub_responses(
|
42
|
+
:list_entities_for_policy,
|
43
|
+
{
|
44
|
+
policy_users: [
|
45
|
+
{ user_name: 'fake-user' },
|
46
|
+
{ user_name: 'fake-user-2' }
|
47
|
+
],
|
48
|
+
policy_groups: [
|
49
|
+
{ group_name: 'fake-group' }
|
50
|
+
],
|
51
|
+
policy_roles: [
|
52
|
+
{ role_name: 'fake-policy' }
|
53
|
+
]
|
54
|
+
}
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with a policy' do
|
59
|
+
context 'when the policy does not have a remote resource' do
|
60
|
+
before { expect(iam_policy_attachment).to receive(:remote_resource).and_return(nil) }
|
61
|
+
|
62
|
+
it 'should not have a remote resource' do
|
63
|
+
expect(iam_policy_attachment.remote_resource).to be_nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should create a hash from the response' do
|
68
|
+
remote_resource = iam_policy_attachment.remote_resource_params
|
69
|
+
|
70
|
+
expect(remote_resource[:name]).to eql 'Fake-Aws-Policy'
|
71
|
+
expect(remote_resource[:_terraform_id]).to eql 'arn:aws:iam::aws:policy/xyv/FakeAwsARN'
|
72
|
+
expect(remote_resource[:_geo_id]).to eql 'Fake-Aws-Policy'
|
73
|
+
|
74
|
+
expect(remote_resource[:users].length).to eql(2)
|
75
|
+
expect(remote_resource[:groups].length).to eql(1)
|
76
|
+
expect(remote_resource[:groups].length).to eql(1)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "GeoEngineer::Resources::AwsIamPolicy" do
|
4
|
+
let(:iam_client) { AwsClients.iam }
|
5
|
+
|
4
6
|
common_resource_tests(GeoEngineer::Resources::AwsIamPolicy,
|
5
7
|
'aws_iam_policy')
|
6
8
|
|
9
|
+
before { iam_client.setup_stubbing }
|
10
|
+
|
7
11
|
describe "#_fetch_remote_resources" do
|
8
12
|
it 'should create list of hashes from returned AWS SDK' do
|
9
|
-
|
10
|
-
# iam.list_policies.policies
|
11
|
-
stub = iam.stub_data(
|
13
|
+
iam_client.stub_responses(
|
12
14
|
:list_policies,
|
13
15
|
{
|
14
16
|
policies: [
|
@@ -27,7 +29,6 @@ describe("GeoEngineer::Resources::AwsIamPolicy") do
|
|
27
29
|
]
|
28
30
|
}
|
29
31
|
)
|
30
|
-
sns.stub_responses(:list_policies, stub)
|
31
32
|
remote_resources = GeoEngineer::Resources::AwsIamPolicy._fetch_remote_resources
|
32
33
|
expect(remote_resources.length).to eq 2
|
33
34
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "GeoEngineer::Resources::AwsIamRole" do
|
4
|
+
let(:aws_client) { AwsClients.iam }
|
5
|
+
|
6
|
+
common_resource_tests(GeoEngineer::Resources::AwsIamRole, 'aws_iam_role')
|
7
|
+
|
8
|
+
before { aws_client.setup_stubbing }
|
9
|
+
|
10
|
+
describe "#_fetch_remote_resources" do
|
11
|
+
before do
|
12
|
+
aws_client.stub_responses(
|
13
|
+
:list_roles, { roles: [
|
14
|
+
{
|
15
|
+
role_name: 'Some-IAM-role',
|
16
|
+
arn: "arn:aws:iam::123456789123:role/some-iam-role",
|
17
|
+
path: "/",
|
18
|
+
role_id: "XXXXXXXXXXXXXXXXXXXXY",
|
19
|
+
create_date: Time.parse("2016-12-13 01:00:06 UTC"),
|
20
|
+
assume_role_policy_document: ""
|
21
|
+
},
|
22
|
+
{
|
23
|
+
role_name: 'Another-IAM-role',
|
24
|
+
arn: "arn:aws:iam::123456789123:role/another-iam-role",
|
25
|
+
path: "/",
|
26
|
+
role_id: "XXXXXXXXXXXXXXXXXXXXY",
|
27
|
+
create_date: Time.parse("2016-12-13 01:00:06 UTC"),
|
28
|
+
assume_role_policy_document: ""
|
29
|
+
}
|
30
|
+
] }
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create a list of hashes from the AWS SDK' do
|
35
|
+
remote_resources = GeoEngineer::Resources::AwsIamRole._fetch_remote_resources
|
36
|
+
expect(remote_resources.length).to eql 2
|
37
|
+
|
38
|
+
test_role = remote_resources.first
|
39
|
+
|
40
|
+
expect(test_role[:_terraform_id]).to eql('Some-IAM-role')
|
41
|
+
expect(test_role[:_geo_id]).to eql('Some-IAM-role')
|
42
|
+
expect(test_role[:name]).to eql('Some-IAM-role')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe("GeoEngineer::Resources::AwsInternetGateway") do
|
4
|
+
common_resource_tests(GeoEngineer::Resources::AwsInternetGateway, 'aws_internet_gateway')
|
5
|
+
name_tag_geo_id_tests(GeoEngineer::Resources::AwsInternetGateway)
|
6
|
+
|
7
|
+
describe "#_fetch_remote_resources" do
|
8
|
+
it 'should create list of hashes from returned AWS SDK' do
|
9
|
+
ec2 = AwsClients.ec2
|
10
|
+
stub = ec2.stub_data(
|
11
|
+
:describe_internet_gateways,
|
12
|
+
{
|
13
|
+
internet_gateways: [
|
14
|
+
{ internet_gateway_id: 'name1', tags: [{ key: 'Name', value: 'one' }] },
|
15
|
+
{ internet_gateway_id: 'name2', tags: [{ key: 'Name', value: 'two' }] }
|
16
|
+
]
|
17
|
+
}
|
18
|
+
)
|
19
|
+
ec2.stub_responses(:describe_internet_gateways, stub)
|
20
|
+
remote_resources = GeoEngineer::Resources::AwsInternetGateway._fetch_remote_resources
|
21
|
+
expect(remote_resources.length).to eq(2)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe("GeoEngineer::Resources::AwsLambdaAlias") do
|
4
|
+
let(:aws_client) { AwsClients.lambda }
|
5
|
+
|
6
|
+
before { aws_client.setup_stubbing }
|
7
|
+
|
8
|
+
common_resource_tests(GeoEngineer::Resources::AwsLambdaAlias, 'aws_lambda_alias')
|
9
|
+
|
10
|
+
describe "#_fetch_remote_resources" do
|
11
|
+
before do
|
12
|
+
aws_client.stub_responses(
|
13
|
+
:list_functions, {
|
14
|
+
functions: [
|
15
|
+
{ function_name: "foo", role: "arn:aws:iam:one", handler: "export.foo" },
|
16
|
+
{ function_name: "bar", role: "arn:aws:iam:two", handler: "export.bar" }
|
17
|
+
]
|
18
|
+
}
|
19
|
+
)
|
20
|
+
aws_client.stub_responses(
|
21
|
+
:list_aliases, {
|
22
|
+
aliases: [
|
23
|
+
{ name: "foonew", alias_arn: "arn:aws:lambda:alias", function_version: "1" }
|
24
|
+
]
|
25
|
+
}
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
aws_client.stub_responses(:list_functions, {})
|
31
|
+
aws_client.stub_responses(:list_aliases, {})
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create list of hashes from returned AWS SDK' do
|
35
|
+
remote_resources = GeoEngineer::Resources::AwsLambdaAlias._fetch_remote_resources
|
36
|
+
expect(remote_resources.length).to eq(2)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe GeoEngineer::Resources::AwsLambdaEventSourceMapping do
|
4
|
+
let(:aws_client) { AwsClients.lambda }
|
5
|
+
|
6
|
+
before { aws_client.setup_stubbing }
|
7
|
+
|
8
|
+
common_resource_tests(
|
9
|
+
GeoEngineer::Resources::AwsLambdaEventSourceMapping,
|
10
|
+
'aws_lambda_event_source_mapping'
|
11
|
+
)
|
12
|
+
|
13
|
+
describe '#_fetch_remote_resources' do
|
14
|
+
before do
|
15
|
+
aws_client.stub_responses(
|
16
|
+
:list_event_source_mappings, {
|
17
|
+
event_source_mappings: [
|
18
|
+
{
|
19
|
+
uuid: "1",
|
20
|
+
event_source_arn: "arn:aws:kinesis:one",
|
21
|
+
function_arn: "arn:aws:lambda:function:foo"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
uuid: "2",
|
25
|
+
event_source_arn: "arn:aws:kinesis:two",
|
26
|
+
function_arn: "arn:aws:lambda:function:bar:beta"
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
after { aws_client.stub_responses(:list_event_source_mappings, {}) }
|
34
|
+
|
35
|
+
it 'should create an array of hashes from the AWS response' do
|
36
|
+
resources = GeoEngineer::Resources::AwsLambdaEventSourceMapping._fetch_remote_resources
|
37
|
+
expect(resources.count).to eql(2)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#_extract_name_from_arn" do
|
42
|
+
it "returns nil if ARN does not contain function" do
|
43
|
+
expect(described_class._extract_name_from_arn("foo_bar")).to be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns item directly after function in ARN" do
|
47
|
+
expect(described_class._extract_name_from_arn("function:bar")).to eq('bar')
|
48
|
+
expect(described_class._extract_name_from_arn("aws:function:baz")).to eq('baz')
|
49
|
+
expect(described_class._extract_name_from_arn("aws:function:foo:qux")).to eq('foo')
|
50
|
+
expect(described_class._extract_name_from_arn("aws:function")).to be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe("GeoEngineer::Resources::AwsLambdaFunction") do
|
4
|
+
let(:aws_client) { AwsClients.lambda }
|
5
|
+
|
6
|
+
before { aws_client.setup_stubbing }
|
7
|
+
|
8
|
+
common_resource_tests(GeoEngineer::Resources::AwsLambdaFunction, 'aws_lambda_function')
|
9
|
+
|
10
|
+
describe '#_fetch_remote_resources' do
|
11
|
+
before do
|
12
|
+
aws_client.stub_responses(
|
13
|
+
:list_functions, {
|
14
|
+
functions: [
|
15
|
+
{ function_name: "foo", role: "arn:aws:iam:one", handler: "export.foo" },
|
16
|
+
{ function_name: "bar", role: "arn:aws:iam:two", handler: "export.bar" }
|
17
|
+
]
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
after { aws_client.stub_responses(:list_functions, {}) }
|
23
|
+
|
24
|
+
it 'should create an array of hashes from the AWS response' do
|
25
|
+
resources = GeoEngineer::Resources::AwsLambdaFunction._fetch_remote_resources
|
26
|
+
expect(resources.count).to eql(2)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe GeoEngineer::Resources::AwsLambdaPermission do
|
4
|
+
let(:aws_client) { AwsClients.lambda }
|
5
|
+
|
6
|
+
before { aws_client.setup_stubbing }
|
7
|
+
|
8
|
+
common_resource_tests(GeoEngineer::Resources::AwsLambdaPermission, 'aws_lambda_permission')
|
9
|
+
|
10
|
+
describe "#_fetch_remote_resources" do
|
11
|
+
before do
|
12
|
+
aws_client.stub_responses(
|
13
|
+
:list_functions, {
|
14
|
+
functions: [
|
15
|
+
{ function_name: "foo", role: "arn:aws:iam:one", handler: "export.foo", version: "1" },
|
16
|
+
{ function_name: "bar", role: "arn:aws:iam:two", handler: "export.bar", version: "1" }
|
17
|
+
]
|
18
|
+
}
|
19
|
+
)
|
20
|
+
aws_client.stub_responses(
|
21
|
+
:get_policy, {
|
22
|
+
policy: { Statement: [{ Sid: Random.rand(1000).to_s }] }.to_json
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
aws_client.stub_responses(:list_functions, {})
|
29
|
+
aws_client.stub_responses(:get_policy, {})
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create list of hashes from returned AWS SDK' do
|
33
|
+
remote_resources = GeoEngineer::Resources::AwsLambdaPermission._fetch_remote_resources
|
34
|
+
expect(remote_resources.length).to eq(2)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#_parse_policy' do
|
39
|
+
it "returns nil is there is a JSON Parse error" do
|
40
|
+
expect(described_class._parse_policy("{ foo: }")).to eq(nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with valid JSON" do
|
44
|
+
it "returns a hash with symbols for keys" do
|
45
|
+
policy = { foo: "bar", baz: ["qux"] }
|
46
|
+
|
47
|
+
expect(described_class._parse_policy(policy.to_json)).to eq(policy)
|
48
|
+
expect(described_class._parse_policy(policy.to_json).include?(:foo)).to eq(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#_deep_symbolize_keys' do
|
54
|
+
let(:simple_obj) { JSON.parse({ foo: "bar", baz: "qux" }.to_json) }
|
55
|
+
let(:complex_obj) do
|
56
|
+
JSON.parse(
|
57
|
+
{
|
58
|
+
foo: {
|
59
|
+
bar: {
|
60
|
+
baz: [
|
61
|
+
{ qux: "quack" }
|
62
|
+
]
|
63
|
+
}
|
64
|
+
},
|
65
|
+
bar: [
|
66
|
+
{ foo: "bar" },
|
67
|
+
nil,
|
68
|
+
[{ baz: "qux" }],
|
69
|
+
1,
|
70
|
+
"baz"
|
71
|
+
]
|
72
|
+
}.to_json
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "converts top level keys to symbols" do
|
77
|
+
expect(simple_obj.keys.include?(:foo)).to eq(false)
|
78
|
+
expect(simple_obj.keys.include?("foo")).to eq(true)
|
79
|
+
converted = described_class._deep_symbolize_keys(simple_obj)
|
80
|
+
expect(converted.keys.include?(:foo)).to eq(true)
|
81
|
+
expect(converted.keys.include?("foo")).to eq(false)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "converts deeply nested keys to symbols" do
|
85
|
+
converted = described_class._deep_symbolize_keys(complex_obj)
|
86
|
+
expect(converted[:foo][:bar][:baz].first[:qux]).to eq("quack")
|
87
|
+
expect(converted[:bar].first[:foo]).to eq("bar")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe GeoEngineer::Resources::AwsMainRouteTableAssociation do
|
4
|
+
common_resource_tests(
|
5
|
+
GeoEngineer::Resources::AwsMainRouteTableAssociation,
|
6
|
+
'aws_main_route_table_association'
|
7
|
+
)
|
8
|
+
|
9
|
+
describe "#_fetch_remote_resources" do
|
10
|
+
let(:ec2) { AwsClients.ec2 }
|
11
|
+
before do
|
12
|
+
stub = ec2.stub_data(
|
13
|
+
:describe_route_tables,
|
14
|
+
{
|
15
|
+
route_tables: [
|
16
|
+
{
|
17
|
+
route_table_id: 'name1',
|
18
|
+
vpc_id: "1",
|
19
|
+
tags: [{ key: 'Name', value: 'one' }],
|
20
|
+
associations: [
|
21
|
+
{
|
22
|
+
route_table_association_id: '1',
|
23
|
+
subnet_id: 's-1',
|
24
|
+
route_table_id: 'r-1',
|
25
|
+
main: false
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
route_table_id: 'name2',
|
31
|
+
vpc_id: "1",
|
32
|
+
tags: [{ key: 'Name', value: 'two' }],
|
33
|
+
associations: [
|
34
|
+
{
|
35
|
+
route_table_association_id: '2',
|
36
|
+
subnet_id: 's-2',
|
37
|
+
route_table_id: 'r-2',
|
38
|
+
main: true
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
)
|
45
|
+
ec2.stub_responses(:describe_route_tables, stub)
|
46
|
+
end
|
47
|
+
|
48
|
+
after do
|
49
|
+
ec2.stub_responses(:describe_route_tables, [])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should create list of hashes from returned AWS SDK' do
|
53
|
+
remote_resources = described_class._fetch_remote_resources
|
54
|
+
expect(remote_resources.length).to eq(1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|