Documentation ¶
Index ¶
- func Capture_IsMatcher(x interface{}) *bool
- func Matcher_IsMatcher(x interface{}) *bool
- func NewCapture_Override(c Capture, pattern interface{})
- func NewMatchResult_Override(m MatchResult, target interface{})
- func NewMatch_Override(m Match)
- func NewMatcher_Override(m Matcher)
- type Annotations
- type Capture
- type Match
- type MatchCapture
- type MatchFailure
- type MatchResult
- type Matcher
- func Match_Absent() Matcher
- func Match_AnyValue() Matcher
- func Match_ArrayEquals(pattern *[]interface{}) Matcher
- func Match_ArrayWith(pattern *[]interface{}) Matcher
- func Match_Exact(pattern interface{}) Matcher
- func Match_Not(pattern interface{}) Matcher
- func Match_ObjectEquals(pattern *map[string]interface{}) Matcher
- func Match_ObjectLike(pattern *map[string]interface{}) Matcher
- func Match_SerializedJson(pattern interface{}) Matcher
- func Match_StringLikeRegexp(pattern *string) Matcher
- type Tags
- type Template
- type TemplateParsingOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capture_IsMatcher ¶
func Capture_IsMatcher(x interface{}) *bool
Check whether the provided object is a subtype of the `IMatcher`.
func Matcher_IsMatcher ¶
func Matcher_IsMatcher(x interface{}) *bool
Check whether the provided object is a subtype of the `IMatcher`.
func NewCapture_Override ¶
func NewCapture_Override(c Capture, pattern interface{})
Initialize a new capture.
func NewMatchResult_Override ¶
func NewMatchResult_Override(m MatchResult, target interface{})
func NewMatch_Override ¶
func NewMatch_Override(m Match)
func NewMatcher_Override ¶
func NewMatcher_Override(m Matcher)
Types ¶
type Annotations ¶ added in v2.10.0
type Annotations interface { // Get the set of matching errors of a given construct path and message. FindError(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage // Get the set of matching infos of a given construct path and message. FindInfo(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage // Get the set of matching warning of a given construct path and message. FindWarning(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage // Assert that an error with the given message exists in the synthesized CDK `Stack`. HasError(constructPath *string, message interface{}) // Assert that an info with the given message exists in the synthesized CDK `Stack`. HasInfo(constructPath *string, message interface{}) // Assert that an error with the given message does not exist in the synthesized CDK `Stack`. HasNoError(constructPath *string, message interface{}) // Assert that an info with the given message does not exist in the synthesized CDK `Stack`. HasNoInfo(constructPath *string, message interface{}) // Assert that an warning with the given message does not exist in the synthesized CDK `Stack`. HasNoWarning(constructPath *string, message interface{}) // Assert that an warning with the given message exists in the synthesized CDK `Stack`. HasWarning(constructPath *string, message interface{}) }
Suite of assertions that can be run on a CDK Stack.
Focused on asserting annotations.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import cdk "github.com/aws/aws-cdk-go/awscdk" import "github.com/aws/aws-cdk-go/awscdk" var stack stack annotations := awscdk.Assertions.Annotations_FromStack(stack)
func Annotations_FromStack ¶ added in v2.10.0
func Annotations_FromStack(stack awscdk.Stack) Annotations
Base your assertions on the messages returned by a synthesized CDK `Stack`.
type Capture ¶
type Capture interface { Matcher // A name for the matcher. // // This is collected as part of the result and may be presented to the user. Name() *string // Retrieve the captured value as an array. // // An error is generated if no value is captured or if the value is not an array. AsArray() *[]interface{} // Retrieve the captured value as a boolean. // // An error is generated if no value is captured or if the value is not a boolean. AsBoolean() *bool // Retrieve the captured value as a number. // // An error is generated if no value is captured or if the value is not a number. AsNumber() *float64 // Retrieve the captured value as a JSON object. // // An error is generated if no value is captured or if the value is not an object. AsObject() *map[string]interface{} // Retrieve the captured value as a string. // // An error is generated if no value is captured or if the value is not a string. AsString() *string // When multiple results are captured, move the iterator to the next result. // // Returns: true if another capture is present, false otherwise. Next() *bool // Test whether a target matches the provided pattern. // // Every Matcher must implement this method. // This method will be invoked by the assertions framework. Do not call this method directly. Test(actual interface{}) MatchResult }
Capture values while matching templates.
Using an instance of this class within a Matcher will capture the matching value. The `as*()` APIs on the instance can be used to get the captured value.
Example:
// Given a template - // { // "Resources": { // "MyBar": { // "Type": "Foo::Bar", // "Properties": { // "Fred": "Flob", // } // }, // "MyBaz": { // "Type": "Foo::Bar", // "Properties": { // "Fred": "Quib", // } // } // } // } fredCapture := awscdk.NewCapture() template.HasResourceProperties(jsii.String("Foo::Bar"), map[string]capture{ "Fred": fredCapture, }) fredCapture.AsString() // returns "Flob" fredCapture.Next() // returns true fredCapture.AsString()
type MatchCapture ¶ added in v2.1.0
type MatchCapture struct { // The instance of Capture class to which this capture is associated with. Capture Capture `field:"required" json:"capture" yaml:"capture"` // The value that was captured. Value interface{} `field:"required" json:"value" yaml:"value"` }
Information about a value captured during match.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import "github.com/aws/aws-cdk-go/awscdk" var capture capture var value interface{} matchCapture := &MatchCapture{ Capture: capture, Value: value, }
type MatchFailure ¶ added in v2.1.0
type MatchFailure struct { // The matcher that had the failure. Matcher Matcher `field:"required" json:"matcher" yaml:"matcher"` // Failure message. Message *string `field:"required" json:"message" yaml:"message"` // The relative path in the target where the failure occurred. // // If the failure occurred at root of the match tree, set the path to an empty list. // If it occurs in the 5th index of an array nested within the 'foo' key of an object, // set the path as `['/foo', '[5]']`. Path *[]*string `field:"required" json:"path" yaml:"path"` // The cost of this particular mismatch. // Default: 1. // Cost *float64 `field:"optional" json:"cost" yaml:"cost"` }
Match failure details.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import "github.com/aws/aws-cdk-go/awscdk" var matcher matcher matchFailure := &MatchFailure{ Matcher: matcher, Message: jsii.String("message"), Path: []*string{ jsii.String("path"), }, // the properties below are optional Cost: jsii.Number(123), }
type MatchResult ¶
type MatchResult interface { // The cost of the failures so far. FailCost() *float64 // The number of failures. FailCount() *float64 // Whether the match is a success. IsSuccess() *bool // The target for which this result was generated. Target() interface{} // Compose the results of a previous match as a subtree. Compose(id *string, inner MatchResult) MatchResult // Prepare the result to be analyzed. // // This API *must* be called prior to analyzing these results. Finished() MatchResult // Does the result contain any failures. // // If not, the result is a success. HasFailed() *bool // DEPRECATED. // Deprecated: use recordFailure(). Push(matcher Matcher, path *[]*string, message *string) MatchResult // Record a capture against in this match result. RecordCapture(options *MatchCapture) // Record a new failure into this result at a specific path. RecordFailure(failure *MatchFailure) MatchResult // Do a deep render of the match result, showing the structure mismatches in context. RenderMismatch() *string // Render the failed match in a presentable way. // // Prefer using `renderMismatch` over this method. It is left for backwards // compatibility for test suites that expect it, but `renderMismatch()` will // produce better output. ToHumanStrings() *[]*string }
The result of `Match.test()`.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import "github.com/aws/aws-cdk-go/awscdk" var target interface{} matchResult := awscdk.Assertions.NewMatchResult(target)
func NewMatchResult ¶
func NewMatchResult(target interface{}) MatchResult
type Matcher ¶
type Matcher interface { // A name for the matcher. // // This is collected as part of the result and may be presented to the user. Name() *string // Test whether a target matches the provided pattern. // // Every Matcher must implement this method. // This method will be invoked by the assertions framework. Do not call this method directly. // // Returns: the list of match failures. An empty array denotes a successful match. Test(actual interface{}) MatchResult }
Represents a matcher that can perform special data matching capabilities between a given pattern and a target.
Example:
// Given a template - // { // "Resources": { // "MyBar": { // "Type": "Foo::Bar", // "Properties": { // "Fred": { // "Wobble": ["Flob", "Flib"], // } // } // } // } // } // The following will NOT throw an assertion error template.HasResourceProperties(jsii.String("Foo::Bar"), map[string]map[string][]matcher{ "Fred": map[string][]matcher{ "Wobble": []matcher{ awscdk.Match_anyValue(), awscdk.Match_anyValue(), }, }, }) // The following will throw an assertion error template.HasResourceProperties(jsii.String("Foo::Bar"), map[string]map[string]matcher{ "Fred": map[string]matcher{ "Wimble": awscdk.Match_anyValue(), }, })
func Match_Absent ¶
func Match_Absent() Matcher
Use this matcher in the place of a field's value, if the field must not be present.
func Match_ArrayEquals ¶
func Match_ArrayEquals(pattern *[]interface{}) Matcher
Matches the specified pattern with the array found in the same relative path of the target.
The set of elements (or matchers) must match exactly and in order.
func Match_ArrayWith ¶
func Match_ArrayWith(pattern *[]interface{}) Matcher
Matches the specified pattern with the array found in the same relative path of the target.
The set of elements (or matchers) must be in the same order as would be found.
func Match_Exact ¶
func Match_Exact(pattern interface{}) Matcher
Deep exact matching of the specified pattern to the target.
func Match_Not ¶
func Match_Not(pattern interface{}) Matcher
Matches any target which does NOT follow the specified pattern.
func Match_ObjectEquals ¶
Matches the specified pattern to an object found in the same relative path of the target.
The keys and their values (or matchers) must match exactly with the target.
func Match_ObjectLike ¶
Matches the specified pattern to an object found in the same relative path of the target.
The keys and their values (or matchers) must be present in the target but the target can be a superset.
func Match_SerializedJson ¶
func Match_SerializedJson(pattern interface{}) Matcher
Matches any string-encoded JSON and applies the specified pattern after parsing it.
func Match_StringLikeRegexp ¶ added in v2.9.0
Matches targets according to a regular expression.
type Tags ¶ added in v2.137.0
type Tags interface { // Get the tags associated with the manifest. // // This will be an empty object if // no tags were supplied. // // Returns: The tags associated with the stack's synthesized manifest. All() *map[string]*string // Assert that the there are no tags associated with the synthesized CDK Stack's manifest. // // This is a convenience method over `hasValues(Match.exact({}))`, and is // present because the more obvious method of detecting no tags // (`Match.absent()`) will not work. Manifests default the tag set to an empty // object. HasNone() // Assert that the given Matcher or object matches the tags associated with the synthesized CDK Stack's manifest. HasValues(tags interface{}) }
Allows assertions on the tags associated with a synthesized CDK stack's manifest.
Stack tags are not part of the synthesized template, so can only be checked from the manifest in this manner.
Example:
tags := awscdk.Tags_FromStack(stack) // using a default 'objectLike' Matcher tags.HasValues(map[string]*string{ "tag-name": jsii.String("tag-value"), }) // ... with Matchers embedded tags.HasValues(map[string]matcher{ "tag-name": awscdk.Match_stringLikeRegexp(jsii.String("value")), }) // or another object Matcher at the top level tags.HasValues(awscdk.Match_ObjectEquals(map[string]interface{}{ "tag-name": awscdk.Match_anyValue(), }))
func Tags_FromStack ¶ added in v2.137.0
func Tags_FromStack(stack awscdk.Stack) Tags
Find tags associated with a synthesized CDK `Stack`.
type Template ¶
type Template interface { // 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. AllResources(type_ *string, props interface{}) // 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. AllResourcesProperties(type_ *string, props interface{}) // Get the set of matching Conditions that match the given properties in the CloudFormation template. FindConditions(logicalId *string, props interface{}) *map[string]*map[string]interface{} // Get the set of matching Mappings that match the given properties in the CloudFormation template. FindMappings(logicalId *string, props interface{}) *map[string]*map[string]interface{} // Get the set of matching Outputs that match the given properties in the CloudFormation template. FindOutputs(logicalId *string, props interface{}) *map[string]*map[string]interface{} // Get the set of matching Parameters that match the given properties in the CloudFormation template. FindParameters(logicalId *string, props interface{}) *map[string]*map[string]interface{} // Get the set of matching resources of a given type and properties in the CloudFormation template. FindResources(type_ *string, props interface{}) *map[string]*map[string]interface{} // 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. HasCondition(logicalId *string, props interface{}) // 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. HasMapping(logicalId *string, props interface{}) // 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. HasOutput(logicalId *string, props interface{}) // 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. HasParameter(logicalId *string, props interface{}) // 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. HasResource(type_ *string, props interface{}) // 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. HasResourceProperties(type_ *string, props interface{}) // Assert that the given number of resources of the given type exist in the template. ResourceCountIs(type_ *string, count *float64) // Assert that the given number of resources of the given type and properties exists in the CloudFormation template. ResourcePropertiesCountIs(type_ *string, props interface{}, count *float64) // Assert that the CloudFormation template matches the given value. TemplateMatches(expected interface{}) // The CloudFormation template deserialized into an object. ToJSON() *map[string]interface{} }
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.
Example:
import "github.com/aws/aws-cdk-go/awscdk" import "github.com/aws/aws-cdk-go/awscdk" stack := awscdk.NewStack() // ... template := awscdk.Template_FromStack(stack)
func Template_FromJSON ¶
func Template_FromJSON(template *map[string]interface{}, templateParsingOptions *TemplateParsingOptions) Template
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
func Template_FromStack ¶
func Template_FromStack(stack awscdk.Stack, templateParsingOptions *TemplateParsingOptions) Template
Base your assertions on the CloudFormation template synthesized by a CDK `Stack`.
func Template_FromString ¶
func Template_FromString(template *string, templateParsingOptions *TemplateParsingOptions) Template
Base your assertions from an existing CloudFormation template formatted as a JSON string.
type TemplateParsingOptions ¶ added in v2.45.0
type TemplateParsingOptions struct { // If set to true, will skip checking for cyclical / circular dependencies. // // Should be set to false other than for // templates that are valid despite containing cycles, such as unprocessed transform stacks. // Default: false. // SkipCyclicalDependenciesCheck *bool `field:"optional" json:"skipCyclicalDependenciesCheck" yaml:"skipCyclicalDependenciesCheck"` }
Options to configure template parsing behavior, such as disregarding circular dependencies.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import "github.com/aws/aws-cdk-go/awscdk" templateParsingOptions := &TemplateParsingOptions{ SkipCyclicalDependenciesCheck: jsii.Boolean(false), }