chemtrail 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/lib/templates/config/resources.yml +27 -0
- data/examples/lib/templates/opsworks_vpc_template.rb +47 -2
- data/examples/spec/lib/templates/opsworks_vpc_template_spec.rb +29 -0
- data/lib/chemtrail.rb +1 -0
- data/lib/chemtrail/intrinsic.rb +17 -0
- data/lib/chemtrail/matchers/have_field.rb +56 -0
- data/lib/chemtrail/matchers/have_mapping.rb +9 -0
- data/lib/chemtrail/matchers/have_mapping_key.rb +49 -0
- data/lib/chemtrail/matchers/have_parameter.rb +31 -0
- data/lib/chemtrail/matchers/have_property.rb +59 -0
- data/lib/chemtrail/matchers/have_resource.rb +31 -0
- data/lib/chemtrail/matchers/have_tag.rb +60 -0
- data/lib/chemtrail/resource.rb +2 -1
- data/lib/chemtrail/rspec.rb +7 -130
- data/lib/chemtrail/version.rb +1 -1
- data/spec/lib/chemtrail/intrinsic_spec.rb +14 -0
- data/spec/lib/chemtrail/resource_spec.rb +7 -2
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c327599b79192343d3993d9b30c9a5535e711ff
|
4
|
+
data.tar.gz: 0f2e7925ba1bcb70e468e9059a004dc78325205c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee99fa18b8a65a03fe64fdc5e1ba13a21a2e85628b1ede78a092e946dbe6a8c76ba268131184865d0d27187ab1bc8c019b48d1844ff53f1cb1f6dc9f8f7c6d9
|
7
|
+
data.tar.gz: 90fdf39a9da0d664ea6a7eb4f49a497fd7f31696a3ecf0fd2cd5a329f66e5f6f4aeab6df61dd4e69345e8cefd078f716ab593242dab53af38ce1176a80a62f79
|
@@ -0,0 +1,27 @@
|
|
1
|
+
VPC:
|
2
|
+
Tags:
|
3
|
+
- Key: Network
|
4
|
+
Value: Public
|
5
|
+
|
6
|
+
PublicSubnet:
|
7
|
+
Tags:
|
8
|
+
- Key: Network
|
9
|
+
Value: Public
|
10
|
+
|
11
|
+
InternetGateway:
|
12
|
+
Tags:
|
13
|
+
- Key: Network
|
14
|
+
Value: Public
|
15
|
+
|
16
|
+
PublicRoute:
|
17
|
+
DestinationCidrBlock: 0.0.0.0/0
|
18
|
+
|
19
|
+
InboundHTTPPublicNetworkAclEntry:
|
20
|
+
RuleNumber: "100"
|
21
|
+
Protocol: "6"
|
22
|
+
RuleAction: allow
|
23
|
+
Egress: false
|
24
|
+
CidrBlock: 0.0.0.0/0
|
25
|
+
PortRange:
|
26
|
+
From: "80"
|
27
|
+
To: "80"
|
@@ -11,7 +11,7 @@ class OpsworksVpc < Chemtrail::Template
|
|
11
11
|
|
12
12
|
You will be billed for the AWS resources used if you create a stack from
|
13
13
|
this template.
|
14
|
-
|
14
|
+
DESCRIPTION
|
15
15
|
end
|
16
16
|
|
17
17
|
def parameters
|
@@ -24,10 +24,55 @@ class OpsworksVpc < Chemtrail::Template
|
|
24
24
|
[
|
25
25
|
Chemtrail::Mapping.new("AWSNATAMI", mappings_config["AWSNATAMI"]),
|
26
26
|
Chemtrail::Mapping.new("AWSInstanceType2Arch", mappings_config["AWSInstanceType2Arch"]),
|
27
|
-
|
27
|
+
subnet_config
|
28
28
|
]
|
29
29
|
end
|
30
30
|
|
31
|
+
def resources
|
32
|
+
[
|
33
|
+
vpc,
|
34
|
+
public_subnet,
|
35
|
+
internet_gateway,
|
36
|
+
gateway_to_internet
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def subnet_config
|
41
|
+
@subnet_config ||= Chemtrail::Mapping.new("SubnetConfig", mappings_config["SubnetConfig"])
|
42
|
+
end
|
43
|
+
|
44
|
+
def vpc
|
45
|
+
@vpc ||= Chemtrail::Resource.new("VPC", "AWS::EC2::VPC", resources_config["VPC"]).tap do |config|
|
46
|
+
config.properties["CidrBlock"] = subnet_config.find("VPC", "CIDR")
|
47
|
+
config.properties["Tags"] << stack_name.as_tag("Application")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def public_subnet
|
52
|
+
@public_subnet ||= Chemtrail::Resource.new("PublicSubnet", "AWS::EC2::Subnet", resources_config["PublicSubnet"]).tap do |config|
|
53
|
+
config.properties["VpcId"] = vpc
|
54
|
+
config.properties["CidrBlock"] = subnet_config.find("VPC", "CIDR")
|
55
|
+
config.properties["Tags"] << stack_name.as_tag("Application")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def internet_gateway
|
60
|
+
@internet_gateway ||= Chemtrail::Resource.new("InternetGateway", "AWS::EC2::InternetGateway", resources_config["InternetGateway"]).tap do |config|
|
61
|
+
config.properties["Tags"] << stack_name.as_tag("Application")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def gateway_to_internet
|
66
|
+
@gateway_to_internet ||= Chemtrail::Resource.new("GatewayToInternet", "AWS::EC2::VPCGatewayAttachment", resources_config["GatewayToInternet"]).tap do |config|
|
67
|
+
config.properties["VpcId"] = vpc
|
68
|
+
config.properties["InternetGatewayId"] = internet_gateway
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def stack_name
|
73
|
+
@stack_name ||= Chemtrail::Intrinsic.new("AWS::StackName")
|
74
|
+
end
|
75
|
+
|
31
76
|
protected
|
32
77
|
|
33
78
|
def parameters_config
|
@@ -26,5 +26,34 @@ describe OpsworksVpc do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#resources" do
|
29
|
+
describe "VPC" do
|
30
|
+
it { should have_resource("VPC").with_type("AWS::EC2::VPC") }
|
31
|
+
|
32
|
+
it { should have_property("CidrBlock").on("VPC") }
|
33
|
+
it { should have_tag("Application").with_reference("AWS::StackName").on("VPC") }
|
34
|
+
it { should have_tag("Network").with_value("Public").on("VPC") }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "PublicSubnet" do
|
38
|
+
it { should have_resource("PublicSubnet").with_type("AWS::EC2::Subnet") }
|
39
|
+
|
40
|
+
it { should have_property("CidrBlock").on("PublicSubnet") }
|
41
|
+
it { should have_tag("Application").with_reference("AWS::StackName").on("PublicSubnet") }
|
42
|
+
it { should have_tag("Network").with_value("Public").on("PublicSubnet") }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "InternetGateway" do
|
46
|
+
it { should have_resource("InternetGateway").with_type("AWS::EC2::InternetGateway") }
|
47
|
+
|
48
|
+
it { should have_tag("Application").with_reference("AWS::StackName").on("InternetGateway") }
|
49
|
+
it { should have_tag("Network").with_value("Public").on("InternetGateway") }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GatewayToInternet" do
|
53
|
+
it { should have_resource("GatewayToInternet").with_type("AWS::EC2::VPCGatewayAttachment") }
|
54
|
+
|
55
|
+
it { should have_property("VpcId").with_reference("VPC").on("GatewayToInternet") }
|
56
|
+
it { should have_property("InternetGatewayId").with_reference("InternetGateway").on("GatewayToInternet") }
|
57
|
+
end
|
29
58
|
end
|
30
59
|
end
|
data/lib/chemtrail.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_field do |field_name|
|
7
|
+
define_method :parameter_for do |actual|
|
8
|
+
actual.parameters.detect { |p| p.id == @parameter_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :field_for do |parameter|
|
12
|
+
parameter.fields[field_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method :matches_value? do |field|
|
16
|
+
if @value
|
17
|
+
field == @value
|
18
|
+
elsif @included_value
|
19
|
+
field.include?(@included_value)
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
match do |actual|
|
26
|
+
parameter = parameter_for(actual)
|
27
|
+
field = field_for(parameter)
|
28
|
+
!parameter.nil? && !field.nil? && matches_value?(field)
|
29
|
+
end
|
30
|
+
|
31
|
+
chain :on do |parameter_id|
|
32
|
+
@parameter_id = parameter_id
|
33
|
+
end
|
34
|
+
|
35
|
+
chain :with_value do |value|
|
36
|
+
@value = value
|
37
|
+
end
|
38
|
+
|
39
|
+
chain :including do |value|
|
40
|
+
@included_value = value
|
41
|
+
end
|
42
|
+
|
43
|
+
failure_message_for_should do |actual|
|
44
|
+
if parameter = parameter_for(actual)
|
45
|
+
if field = field_for(parameter)
|
46
|
+
expected_field = @value || @included_value
|
47
|
+
%(expected parameter #{@parameter_id.inspect} field #{field_name.inspect} to have value #{expected_field.inspect}, but got #{field.inspect})
|
48
|
+
else
|
49
|
+
%(expected parameter #{@parameter_id.inspect} to have type #{field_name.inspect})
|
50
|
+
end
|
51
|
+
else
|
52
|
+
%(expected to find parameter #{@parameter_id.inspect}, but got nothing)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_mapping_key do |entry_name|
|
7
|
+
define_method :mapping_for do |actual|
|
8
|
+
actual.mappings.detect { |m| m.id == @mapping_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :entry_for do |mapping|
|
12
|
+
mapping.entries[entry_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method :matches_value? do |entry|
|
16
|
+
if @included_value
|
17
|
+
entry.values_at(*@included_value.keys) == @included_value.values
|
18
|
+
else
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
match do |actual|
|
24
|
+
mapping = mapping_for(actual)
|
25
|
+
entry = entry_for(mapping)
|
26
|
+
!mapping.nil? && !entry.nil? && matches_value?(entry)
|
27
|
+
end
|
28
|
+
|
29
|
+
chain :on do |mapping_id|
|
30
|
+
@mapping_id = mapping_id
|
31
|
+
end
|
32
|
+
|
33
|
+
chain :including do |value|
|
34
|
+
@included_value = value
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message_for_should do |actual|
|
38
|
+
if mapping = mapping_for(actual)
|
39
|
+
if entry = entry_for(mapping)
|
40
|
+
%(expected mapping #{@mapping_id.inspect} field #{entry_name.inspect} to have value #{@included_value.inspect}, but got #{entry.inspect})
|
41
|
+
else
|
42
|
+
%(expected mapping #{@mapping_id.inspect} to have type #{entry_name.inspect})
|
43
|
+
end
|
44
|
+
else
|
45
|
+
%(expected to find mapping #{@mapping_id.inspect}, but got nothing)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_parameter do |parameter_id|
|
7
|
+
define_method :parameter_for do |actual|
|
8
|
+
actual.parameters.detect { |param| param.id == parameter_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :matches_type? do |actual|
|
12
|
+
@type.nil? || parameter_for(actual).type == @type
|
13
|
+
end
|
14
|
+
|
15
|
+
match do |actual|
|
16
|
+
!parameter_for(actual).nil? && matches_type?(actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
chain :with_type do |type|
|
20
|
+
@type = type
|
21
|
+
end
|
22
|
+
|
23
|
+
failure_message_for_should do |actual|
|
24
|
+
if parameter = parameter_for(actual)
|
25
|
+
%(expected parameter #{parameter_id.inspect} to have type #{@type.inspect}, but got #{parameter.type.inspect})
|
26
|
+
else
|
27
|
+
%(expected to find parameter #{parameter_id.inspect}, but got nothing)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_property do |property_name|
|
7
|
+
define_method :resource_for do |actual|
|
8
|
+
actual.resources.detect { |resource| resource.id == @resource_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :property_for do |resource|
|
12
|
+
resource.properties[property_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method :matches_value? do |property|
|
16
|
+
if @value
|
17
|
+
property == @value
|
18
|
+
elsif @reference
|
19
|
+
property.id == @reference
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
match do |actual|
|
26
|
+
resource = resource_for(actual)
|
27
|
+
property = property_for(resource)
|
28
|
+
!resource.nil? && !property.nil? && matches_value?(property)
|
29
|
+
end
|
30
|
+
|
31
|
+
chain :on do |resource_id|
|
32
|
+
@resource_id = resource_id
|
33
|
+
end
|
34
|
+
|
35
|
+
chain :with_value do |value|
|
36
|
+
@value = value
|
37
|
+
end
|
38
|
+
|
39
|
+
chain :with_reference do |reference|
|
40
|
+
@reference = reference
|
41
|
+
end
|
42
|
+
|
43
|
+
failure_message_for_should do |actual|
|
44
|
+
if resource = resource_for(actual)
|
45
|
+
if property = property_for(resource)
|
46
|
+
if @value
|
47
|
+
%(expected resource #{@resource_id.inspect} property #{property_name.inspect} to have value #{@value.inspect}, but got #{property.inspect})
|
48
|
+
else
|
49
|
+
%(expected resource #{@resource_id.inspect} property #{property_name.inspect} to refer to #{@reference.inspect}, but got #{property.id.inspect})
|
50
|
+
end
|
51
|
+
else
|
52
|
+
%(expected resource #{@resource_id.inspect} to have property #{property_name.inspect})
|
53
|
+
end
|
54
|
+
else
|
55
|
+
%(expected to find resource #{@resource_id.inspect}, but got nothing)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_resource do |resource_id|
|
7
|
+
define_method :resource_for do |actual|
|
8
|
+
actual.resources.detect { |resource| resource.id == resource_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :matches_type? do |actual|
|
12
|
+
@type.nil? || resource_for(actual).type == @type
|
13
|
+
end
|
14
|
+
|
15
|
+
match do |actual|
|
16
|
+
!resource_for(actual).nil? && matches_type?(actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
chain :with_type do |type|
|
20
|
+
@type = type
|
21
|
+
end
|
22
|
+
|
23
|
+
failure_message_for_should do |actual|
|
24
|
+
if resource = resource_for(actual)
|
25
|
+
%(expected resource #{resource_id.inspect} to have type #{@type.inspect}, but got #{resource.type.inspect})
|
26
|
+
else
|
27
|
+
%(expected to find resource #{resource_id.inspect}, but got nothing)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
module Chemtrail::RSpec
|
4
|
+
extend RSpec::Matchers::DSL
|
5
|
+
|
6
|
+
matcher :have_tag do |key_name|
|
7
|
+
define_method :resource_for do |actual|
|
8
|
+
actual.resources.detect { |resource| resource.id == @resource_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method :tag_for do |resource|
|
12
|
+
tags = resource.properties["Tags"] || []
|
13
|
+
tags.detect { |tag| tag["Key"] == key_name }
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method :matches_value? do |tag|
|
17
|
+
if @value
|
18
|
+
tag["Value"] == @value
|
19
|
+
elsif @reference
|
20
|
+
tag["Value"].id == @reference
|
21
|
+
else
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
match do |actual|
|
27
|
+
resource = resource_for(actual)
|
28
|
+
tag = tag_for(resource)
|
29
|
+
!resource.nil? && !tag.nil? && matches_value?(tag)
|
30
|
+
end
|
31
|
+
|
32
|
+
chain :on do |resource_id|
|
33
|
+
@resource_id = resource_id
|
34
|
+
end
|
35
|
+
|
36
|
+
chain :with_value do |value|
|
37
|
+
@value = value
|
38
|
+
end
|
39
|
+
|
40
|
+
chain :with_reference do |reference|
|
41
|
+
@reference = reference
|
42
|
+
end
|
43
|
+
|
44
|
+
failure_message_for_should do |actual|
|
45
|
+
if resource = resource_for(actual)
|
46
|
+
if tag = tag_for(resource)
|
47
|
+
if @value
|
48
|
+
%(expected resource #{@resource_id.inspect} tag #{key_name.inspect} to have value #{@value.inspect}, but got #{tag["Value"].inspect})
|
49
|
+
else
|
50
|
+
%(expected resource #{@resource_id.inspect} tag #{key_name.inspect} to refer to #{@reference.inspect}, but got #{tag["Value"].id.inspect})
|
51
|
+
end
|
52
|
+
else
|
53
|
+
%(expected resource #{@resource_id.inspect} to have tag #{key_name.inspect})
|
54
|
+
end
|
55
|
+
else
|
56
|
+
%(expected to find resource #{@resource_id.inspect}, but got nothing)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/chemtrail/resource.rb
CHANGED
data/lib/chemtrail/rspec.rb
CHANGED
@@ -1,131 +1,8 @@
|
|
1
1
|
require "chemtrail"
|
2
|
-
require "
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
actual.parameters.detect { |param| param.id == parameter_id }
|
10
|
-
end
|
11
|
-
|
12
|
-
define_method :matches_type? do |actual|
|
13
|
-
@type.nil? || parameter_for(actual).type == @type
|
14
|
-
end
|
15
|
-
|
16
|
-
match do |actual|
|
17
|
-
!parameter_for(actual).nil? && matches_type?(actual)
|
18
|
-
end
|
19
|
-
|
20
|
-
chain :with_type do |type|
|
21
|
-
@type = type
|
22
|
-
end
|
23
|
-
|
24
|
-
failure_message_for_should do |actual|
|
25
|
-
if parameter = parameter_for(actual)
|
26
|
-
%(expected parameter #{parameter_id.inspect} to have type #{@type.inspect}, but got #{parameter.type.inspect})
|
27
|
-
else
|
28
|
-
%(expected to find parameter #{parameter_id.inspect}, but got nothing)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
matcher :have_field do |field_name|
|
34
|
-
define_method :parameter_for do |actual|
|
35
|
-
actual.parameters.detect { |p| p.id == @parameter_id }
|
36
|
-
end
|
37
|
-
|
38
|
-
define_method :field_for do |parameter|
|
39
|
-
parameter.fields[field_name]
|
40
|
-
end
|
41
|
-
|
42
|
-
define_method :matches_value? do |field|
|
43
|
-
if @value
|
44
|
-
field == @value
|
45
|
-
elsif @included_value
|
46
|
-
field.include?(@included_value)
|
47
|
-
else
|
48
|
-
true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
match do |actual|
|
53
|
-
parameter = parameter_for(actual)
|
54
|
-
field = field_for(parameter)
|
55
|
-
!parameter.nil? && !field.nil? && matches_value?(field)
|
56
|
-
end
|
57
|
-
|
58
|
-
chain :on do |parameter_id|
|
59
|
-
@parameter_id = parameter_id
|
60
|
-
end
|
61
|
-
|
62
|
-
chain :with_value do |value|
|
63
|
-
@value = value
|
64
|
-
end
|
65
|
-
|
66
|
-
chain :including do |value|
|
67
|
-
@included_value = value
|
68
|
-
end
|
69
|
-
|
70
|
-
failure_message_for_should do |actual|
|
71
|
-
if parameter = parameter_for(actual)
|
72
|
-
if field = field_for(parameter)
|
73
|
-
expected_field = @value || @included_value
|
74
|
-
%(expected parameter #{@parameter_id.inspect} field #{field_name.inspect} to have value #{expected_field.inspect}, but got #{field.inspect})
|
75
|
-
else
|
76
|
-
%(expected parameter #{@parameter_id.inspect} to have type #{field_name.inspect})
|
77
|
-
end
|
78
|
-
else
|
79
|
-
%(expected to find parameter #{@parameter_id.inspect}, but got nothing)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
matcher :have_mapping do |expected|
|
85
|
-
match { |actual| actual.mappings.any? { |m| m.id == expected } }
|
86
|
-
end
|
87
|
-
|
88
|
-
matcher :have_mapping_key do |entry_name|
|
89
|
-
define_method :mapping_for do |actual|
|
90
|
-
actual.mappings.detect { |m| m.id == @mapping_id }
|
91
|
-
end
|
92
|
-
|
93
|
-
define_method :entry_for do |mapping|
|
94
|
-
mapping.entries[entry_name]
|
95
|
-
end
|
96
|
-
|
97
|
-
define_method :matches_value? do |entry|
|
98
|
-
if @included_value
|
99
|
-
entry.values_at(*@included_value.keys) == @included_value.values
|
100
|
-
else
|
101
|
-
true
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
match do |actual|
|
106
|
-
mapping = mapping_for(actual)
|
107
|
-
entry = entry_for(mapping)
|
108
|
-
!mapping.nil? && !entry.nil? && matches_value?(entry)
|
109
|
-
end
|
110
|
-
|
111
|
-
chain :on do |mapping_id|
|
112
|
-
@mapping_id = mapping_id
|
113
|
-
end
|
114
|
-
|
115
|
-
chain :including do |value|
|
116
|
-
@included_value = value
|
117
|
-
end
|
118
|
-
|
119
|
-
failure_message_for_should do |actual|
|
120
|
-
if mapping = mapping_for(actual)
|
121
|
-
if entry = entry_for(mapping)
|
122
|
-
%(expected mapping #{@mapping_id.inspect} field #{entry_name.inspect} to have value #{@included_value.inspect}, but got #{entry.inspect})
|
123
|
-
else
|
124
|
-
%(expected mapping #{@mapping_id.inspect} to have type #{entry_name.inspect})
|
125
|
-
end
|
126
|
-
else
|
127
|
-
%(expected to find mapping #{@mapping_id.inspect}, but got nothing)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
2
|
+
require "chemtrail/matchers/have_field"
|
3
|
+
require "chemtrail/matchers/have_mapping"
|
4
|
+
require "chemtrail/matchers/have_mapping_key"
|
5
|
+
require "chemtrail/matchers/have_parameter"
|
6
|
+
require "chemtrail/matchers/have_property"
|
7
|
+
require "chemtrail/matchers/have_resource"
|
8
|
+
require "chemtrail/matchers/have_tag"
|
data/lib/chemtrail/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Chemtrail::Intrinsic do
|
4
|
+
subject(:intrinsic) { Chemtrail::Intrinsic.new("Tacos") }
|
5
|
+
|
6
|
+
its(:id) { should == "Tacos" }
|
7
|
+
its(:to_reference) { should == {"Ref" => "Tacos"} }
|
8
|
+
|
9
|
+
describe "#as_tag" do
|
10
|
+
it "creates a tag with the given name" do
|
11
|
+
intrinsic.as_tag("Great").should == {"Key"=>"Great", "Value"=>intrinsic}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,6 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Chemtrail::Resource do
|
4
4
|
subject(:resource) { Chemtrail::Resource.new("toenails", "Gross") }
|
5
|
+
let(:hash) { resource.to_hash["toenails"] }
|
5
6
|
|
6
7
|
its(:id) { should == "toenails" }
|
7
8
|
its(:type) { should == "Gross" }
|
@@ -14,10 +15,14 @@ describe Chemtrail::Resource do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
context "when there is a property" do
|
17
|
-
let(:hash) { resource.to_hash["toenails"] }
|
18
|
-
|
19
18
|
before { resource.properties["UserDingus"] = "whatever" }
|
20
19
|
|
21
20
|
specify { hash["Properties"].should include("UserDingus" => "whatever") }
|
22
21
|
end
|
22
|
+
|
23
|
+
context "when a property is configured through the initializer" do
|
24
|
+
subject(:resource) { Chemtrail::Resource.new("toenails", "Gross", clipping: "great") }
|
25
|
+
|
26
|
+
specify { hash["Properties"].should include(clipping: "great") }
|
27
|
+
end
|
23
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chemtrail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doc Ritezel
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- examples/Guardfile
|
104
104
|
- examples/lib/templates/config/mappings.yml
|
105
105
|
- examples/lib/templates/config/parameters.yml
|
106
|
+
- examples/lib/templates/config/resources.yml
|
106
107
|
- examples/lib/templates/opsworks_vpc_template.rb
|
107
108
|
- examples/spec/lib/templates/opsworks_vpc_template_spec.rb
|
108
109
|
- examples/spec/spec_helper.rb
|
@@ -110,7 +111,15 @@ files:
|
|
110
111
|
- lib/chemtrail/class_name_inflector.rb
|
111
112
|
- lib/chemtrail/cli.rb
|
112
113
|
- lib/chemtrail/function.rb
|
114
|
+
- lib/chemtrail/intrinsic.rb
|
113
115
|
- lib/chemtrail/mapping.rb
|
116
|
+
- lib/chemtrail/matchers/have_field.rb
|
117
|
+
- lib/chemtrail/matchers/have_mapping.rb
|
118
|
+
- lib/chemtrail/matchers/have_mapping_key.rb
|
119
|
+
- lib/chemtrail/matchers/have_parameter.rb
|
120
|
+
- lib/chemtrail/matchers/have_property.rb
|
121
|
+
- lib/chemtrail/matchers/have_resource.rb
|
122
|
+
- lib/chemtrail/matchers/have_tag.rb
|
114
123
|
- lib/chemtrail/output.rb
|
115
124
|
- lib/chemtrail/parameter.rb
|
116
125
|
- lib/chemtrail/property_list.rb
|
@@ -124,6 +133,7 @@ files:
|
|
124
133
|
- spec/lib/chemtrail/class_name_inflector_spec.rb
|
125
134
|
- spec/lib/chemtrail/cli_spec.rb
|
126
135
|
- spec/lib/chemtrail/function_spec.rb
|
136
|
+
- spec/lib/chemtrail/intrinsic_spec.rb
|
127
137
|
- spec/lib/chemtrail/mapping_spec.rb
|
128
138
|
- spec/lib/chemtrail/output_spec.rb
|
129
139
|
- spec/lib/chemtrail/parameter_spec.rb
|
@@ -162,6 +172,7 @@ test_files:
|
|
162
172
|
- spec/lib/chemtrail/class_name_inflector_spec.rb
|
163
173
|
- spec/lib/chemtrail/cli_spec.rb
|
164
174
|
- spec/lib/chemtrail/function_spec.rb
|
175
|
+
- spec/lib/chemtrail/intrinsic_spec.rb
|
165
176
|
- spec/lib/chemtrail/mapping_spec.rb
|
166
177
|
- spec/lib/chemtrail/output_spec.rb
|
167
178
|
- spec/lib/chemtrail/parameter_spec.rb
|