Class: AWSCDK::Assertions::Template
- Inherits:
-
Jsii::Object
- Object
- Jsii::Object
- AWSCDK::Assertions::Template
- Defined in:
- assertions/template.rb
Overview
Suite of assertions that can be run on a CDK stack.
Typically used, as part of unit tests, to validate that the rendered CloudFormation template has expected resources and properties.
Class Method Summary collapse
-
.from_json(template, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
-
.from_stack(stack, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions on the CloudFormation template synthesized by a CDK
Stack. -
.from_string(template, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions from an existing CloudFormation template formatted as a JSON string.
- .jsii_overridable_methods ⇒ Object
Instance Method Summary collapse
-
#all_resources(type, props) ⇒ void
Assert that all resources of the given type contain the given definition in the CloudFormation template.
-
#all_resources_properties(type, props) ⇒ void
Assert that all resources of the given type contain the given properties CloudFormation template.
-
#find_conditions(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Conditions that match the given properties in the CloudFormation template.
-
#find_mappings(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Mappings that match the given properties in the CloudFormation template.
-
#find_outputs(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Outputs that match the given properties in the CloudFormation template.
-
#find_parameters(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Parameters that match the given properties in the CloudFormation template.
-
#find_resources(type, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching resources of a given type and properties in the CloudFormation template.
-
#get_resource_id(type, props = nil) ⇒ String
Get the Resource ID of a matching resource, expects only to find one match.
-
#has_condition(logical_id, props) ⇒ void
Assert that a Condition with the given properties exists in the CloudFormation template.
-
#has_mapping(logical_id, props) ⇒ void
Assert that a Mapping with the given properties exists in the CloudFormation template.
-
#has_output(logical_id, props) ⇒ void
Assert that an Output with the given properties exists in the CloudFormation template.
-
#has_parameter(logical_id, props) ⇒ void
Assert that a Parameter with the given properties exists in the CloudFormation template.
-
#has_resource(type, props) ⇒ void
Assert that a resource of the given type and given definition exists in the CloudFormation template.
-
#has_resource_properties(type, props) ⇒ void
Assert that a resource of the given type and properties exists in the CloudFormation template.
-
#initialize(*args) ⇒ Template
constructor
A new instance of Template.
-
#resource_count_is(type, count) ⇒ void
Assert that the given number of resources of the given type exist in the template.
-
#resource_properties_count_is(type, props, count) ⇒ void
Assert that the given number of resources of the given type and properties exists in the CloudFormation template.
-
#template_matches(expected) ⇒ void
Assert that the CloudFormation template matches the given value.
-
#to_json ⇒ Hash{String => Object}
The CloudFormation template deserialized into an object.
Constructor Details
#initialize(*args) ⇒ Template
Returns a new instance of Template.
11 12 13 |
# File 'assertions/template.rb', line 11 def initialize(*args) raise NoMethodError, "aws-cdk-lib.assertions.Template does not have a visible constructor; use the provided factory methods" end |
Class Method Details
.from_json(template, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
43 44 45 46 47 48 |
# File 'assertions/template.rb', line 43 def self.from_json(template, = nil) Jsii::Type.check_type(template, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6ImFueSJ9LCJraW5kIjoibWFwIn19")), "template") = .is_a?(Hash) ? ::AWSCDK::Assertions::TemplateParsingOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hc3NlcnRpb25zLlRlbXBsYXRlUGFyc2luZ09wdGlvbnMifQ==")), "templateParsingOptions") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.assertions.Template", "fromJSON", [template, ]) end |
.from_stack(stack, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions on the CloudFormation template synthesized by a CDK Stack.
55 56 57 58 59 60 |
# File 'assertions/template.rb', line 55 def self.from_stack(stack, = nil) Jsii::Type.check_type(stack, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5TdGFjayJ9")), "stack") = .is_a?(Hash) ? ::AWSCDK::Assertions::TemplateParsingOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hc3NlcnRpb25zLlRlbXBsYXRlUGFyc2luZ09wdGlvbnMifQ==")), "templateParsingOptions") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.assertions.Template", "fromStack", [stack, ]) end |
.from_string(template, template_parsing_options = nil) ⇒ AWSCDK::Assertions::Template
Base your assertions from an existing CloudFormation template formatted as a JSON string.
67 68 69 70 71 72 |
# File 'assertions/template.rb', line 67 def self.from_string(template, = nil) Jsii::Type.check_type(template, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "template") = .is_a?(Hash) ? ::AWSCDK::Assertions::TemplateParsingOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hc3NlcnRpb25zLlRlbXBsYXRlUGFyc2luZ09wdGlvbnMifQ==")), "templateParsingOptions") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.assertions.Template", "fromString", [template, ]) end |
.jsii_overridable_methods ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'assertions/template.rb', line 15 def self.jsii_overridable_methods { :all_resources => { kind: :method, name: "allResources", is_optional: false }, :all_resources_properties => { kind: :method, name: "allResourcesProperties", is_optional: false }, :find_conditions => { kind: :method, name: "findConditions", is_optional: false }, :find_mappings => { kind: :method, name: "findMappings", is_optional: false }, :find_outputs => { kind: :method, name: "findOutputs", is_optional: false }, :find_parameters => { kind: :method, name: "findParameters", is_optional: false }, :find_resources => { kind: :method, name: "findResources", is_optional: false }, :get_resource_id => { kind: :method, name: "getResourceId", is_optional: false }, :has_condition => { kind: :method, name: "hasCondition", is_optional: false }, :has_mapping => { kind: :method, name: "hasMapping", is_optional: false }, :has_output => { kind: :method, name: "hasOutput", is_optional: false }, :has_parameter => { kind: :method, name: "hasParameter", is_optional: false }, :has_resource => { kind: :method, name: "hasResource", is_optional: false }, :has_resource_properties => { kind: :method, name: "hasResourceProperties", is_optional: false }, :resource_count_is => { kind: :method, name: "resourceCountIs", is_optional: false }, :resource_properties_count_is => { kind: :method, name: "resourcePropertiesCountIs", is_optional: false }, :template_matches => { kind: :method, name: "templateMatches", is_optional: false }, :to_json => { kind: :method, name: "toJSON", is_optional: false }, } end |
Instance Method Details
#all_resources(type, props) ⇒ void
This method returns an undefined value.
Assert that all resources of the given type contain the given definition in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
82 83 84 85 86 |
# File 'assertions/template.rb', line 82 def all_resources(type, props) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("allResources", [type, props]) end |
#all_resources_properties(type, props) ⇒ void
This method returns an undefined value.
Assert that all resources of the given type contain the given properties CloudFormation template.
By default, performs partial matching on the Properties key of the resource, via the
Match.objectLike(). To configure different behavior, use other matchers in the Match class.
96 97 98 99 100 |
# File 'assertions/template.rb', line 96 def all_resources_properties(type, props) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("allResourcesProperties", [type, props]) end |
#find_conditions(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Conditions that match the given properties in the CloudFormation template.
107 108 109 110 111 |
# File 'assertions/template.rb', line 107 def find_conditions(logical_id, props = nil) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("findConditions", [logical_id, props]) end |
#find_mappings(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Mappings that match the given properties in the CloudFormation template.
118 119 120 121 122 |
# File 'assertions/template.rb', line 118 def find_mappings(logical_id, props = nil) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("findMappings", [logical_id, props]) end |
#find_outputs(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Outputs that match the given properties in the CloudFormation template.
129 130 131 132 133 |
# File 'assertions/template.rb', line 129 def find_outputs(logical_id, props = nil) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("findOutputs", [logical_id, props]) end |
#find_parameters(logical_id, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching Parameters that match the given properties in the CloudFormation template.
140 141 142 143 144 |
# File 'assertions/template.rb', line 140 def find_parameters(logical_id, props = nil) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("findParameters", [logical_id, props]) end |
#find_resources(type, props = nil) ⇒ Hash{String => Hash{String => Object}}
Get the set of matching resources of a given type and properties in the CloudFormation template.
151 152 153 154 155 |
# File 'assertions/template.rb', line 151 def find_resources(type, props = nil) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("findResources", [type, props]) end |
#get_resource_id(type, props = nil) ⇒ String
Get the Resource ID of a matching resource, expects only to find one match.
Throws AssertionError if none or multiple resources were found.
164 165 166 167 168 |
# File 'assertions/template.rb', line 164 def get_resource_id(type, props = nil) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") unless props.nil? jsii_call_method("getResourceId", [type, props]) end |
#has_condition(logical_id, props) ⇒ void
This method returns an undefined value.
Assert that a Condition with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
178 179 180 181 182 |
# File 'assertions/template.rb', line 178 def has_condition(logical_id, props) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasCondition", [logical_id, props]) end |
#has_mapping(logical_id, props) ⇒ void
This method returns an undefined value.
Assert that a Mapping with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
192 193 194 195 196 |
# File 'assertions/template.rb', line 192 def has_mapping(logical_id, props) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasMapping", [logical_id, props]) end |
#has_output(logical_id, props) ⇒ void
This method returns an undefined value.
Assert that an Output with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
206 207 208 209 210 |
# File 'assertions/template.rb', line 206 def has_output(logical_id, props) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasOutput", [logical_id, props]) end |
#has_parameter(logical_id, props) ⇒ void
This method returns an undefined value.
Assert that a Parameter with the given properties exists in the CloudFormation template.
By default, performs partial matching on the parameter, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
220 221 222 223 224 |
# File 'assertions/template.rb', line 220 def has_parameter(logical_id, props) Jsii::Type.check_type(logical_id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "logicalId") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasParameter", [logical_id, props]) end |
#has_resource(type, props) ⇒ void
This method returns an undefined value.
Assert that a resource of the given type and given definition exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
234 235 236 237 238 |
# File 'assertions/template.rb', line 234 def has_resource(type, props) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasResource", [type, props]) end |
#has_resource_properties(type, props) ⇒ void
This method returns an undefined value.
Assert that a resource of the given type and properties exists in the CloudFormation template.
By default, performs partial matching on the Properties key of the resource, via the
Match.objectLike(). To configure different behavior, use other matchers in the Match class.
248 249 250 251 252 |
# File 'assertions/template.rb', line 248 def has_resource_properties(type, props) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") jsii_call_method("hasResourceProperties", [type, props]) end |
#resource_count_is(type, count) ⇒ void
This method returns an undefined value.
Assert that the given number of resources of the given type exist in the template.
259 260 261 262 263 |
# File 'assertions/template.rb', line 259 def resource_count_is(type, count) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(count, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "count") jsii_call_method("resourceCountIs", [type, count]) end |
#resource_properties_count_is(type, props, count) ⇒ void
This method returns an undefined value.
Assert that the given number of resources of the given type and properties exists in the CloudFormation template.
271 272 273 274 275 276 |
# File 'assertions/template.rb', line 271 def resource_properties_count_is(type, props, count) Jsii::Type.check_type(type, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "type") Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "props") Jsii::Type.check_type(count, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "count") jsii_call_method("resourcePropertiesCountIs", [type, props, count]) end |
#template_matches(expected) ⇒ void
This method returns an undefined value.
Assert that the CloudFormation template matches the given value.
282 283 284 285 |
# File 'assertions/template.rb', line 282 def template_matches(expected) Jsii::Type.check_type(expected, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "expected") jsii_call_method("templateMatches", [expected]) end |
#to_json ⇒ Hash{String => Object}
The CloudFormation template deserialized into an object.
290 291 292 |
# File 'assertions/template.rb', line 290 def to_json() jsii_call_method("toJSON", []) end |