assertions

package
v1.151.0-devpreview Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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`. Experimental.

func Matcher_IsMatcher

func Matcher_IsMatcher(x interface{}) *bool

Check whether the provided object is a subtype of the `IMatcher`. Experimental.

func NewCapture_Override

func NewCapture_Override(c Capture, pattern interface{})

Initialize a new capture. Experimental.

func NewMatchResult_Override

func NewMatchResult_Override(m MatchResult, target interface{})

Experimental.

func NewMatch_Override

func NewMatch_Override(m Match)

Experimental.

func NewMatcher_Override

func NewMatcher_Override(m Matcher)

Experimental.

Types

type Annotations

type Annotations interface {
	// Get the set of matching errors of a given construct path and message.
	// Experimental.
	FindError(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage
	// Get the set of matching infos of a given construct path and message.
	// Experimental.
	FindInfo(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage
	// Get the set of matching warning of a given construct path and message.
	// Experimental.
	FindWarning(constructPath *string, message interface{}) *[]*cxapi.SynthesisMessage
	// Assert that an error with the given message exists in the synthesized CDK `Stack`.
	// Experimental.
	HasError(constructPath *string, message interface{})
	// Assert that an info with the given message exists in the synthesized CDK `Stack`.
	// Experimental.
	HasInfo(constructPath *string, message interface{})
	// Assert that an error with the given message does not exist in the synthesized CDK `Stack`.
	// Experimental.
	HasNoError(constructPath *string, message interface{})
	// Assert that an info with the given message does not exist in the synthesized CDK `Stack`.
	// Experimental.
	HasNoInfo(constructPath *string, message interface{})
	// Assert that an warning with the given message does not exist in the synthesized CDK `Stack`.
	// Experimental.
	HasNoWarning(constructPath *string, message interface{})
	// Assert that an warning with the given message exists in the synthesized CDK `Stack`.
	// Experimental.
	HasWarning(constructPath *string, message interface{})
}

Suite of assertions that can be run on a CDK Stack.

Focused on asserting annotations.

Example:

import monocdk "github.com/aws/aws-cdk-go/awscdk"import awscdk "github.com/aws/aws-cdk-go/awscdk"import assertions "github.com/aws/aws-cdk-go/awscdk/assertions"

var stack stack
annotations := assertions.annotations.fromStack(stack)

Experimental.

func Annotations_FromStack

func Annotations_FromStack(stack awscdk.Stack) Annotations

Base your assertions on the messages returned by a synthesized CDK `Stack`. Experimental.

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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	AsString() *string
	// When multiple results are captured, move the iterator to the next result.
	//
	// Returns: true if another capture is present, false otherwise.
	// Experimental.
	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.
	// Experimental.
	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 := NewCapture()
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]capture{
	"Fred": fredCapture,
})

fredCapture.asString() // returns "Flob"
fredCapture.next() // returns true
fredCapture.asString()

Experimental.

func NewCapture

func NewCapture(pattern interface{}) Capture

Initialize a new capture. Experimental.

type Match

type Match interface {
}

Partial and special matching during template assertions. Experimental.

type MatchCapture

type MatchCapture struct {
	// The instance of Capture class to which this capture is associated with.
	// Experimental.
	Capture Capture `json:"capture" yaml:"capture"`
	// The value that was captured.
	// Experimental.
	Value interface{} `json:"value" yaml:"value"`
}

Information about a value captured during match.

Example:

import awscdk "github.com/aws/aws-cdk-go/awscdk"import assertions "github.com/aws/aws-cdk-go/awscdk/assertions"

var capture capture
var value interface{}
matchCapture := &matchCapture{
	capture: capture,
	value: value,
}

Experimental.

type MatchFailure

type MatchFailure struct {
	// The matcher that had the failure.
	// Experimental.
	Matcher Matcher `json:"matcher" yaml:"matcher"`
	// Failure message.
	// Experimental.
	Message *string `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]']`.
	// Experimental.
	Path *[]*string `json:"path" yaml:"path"`
}

Match failure details.

Example:

import awscdk "github.com/aws/aws-cdk-go/awscdk"import assertions "github.com/aws/aws-cdk-go/awscdk/assertions"

var matcher matcher
matchFailure := &matchFailure{
	matcher: matcher,
	message: jsii.String("message"),
	path: []*string{
		jsii.String("path"),
	},
}

Experimental.

type MatchResult

type MatchResult interface {
	// The number of failures.
	// Experimental.
	FailCount() *float64
	// The target for which this result was generated.
	// Experimental.
	Target() interface{}
	// Compose the results of a previous match as a subtree.
	// Experimental.
	Compose(id *string, inner MatchResult) MatchResult
	// Prepare the result to be analyzed.
	//
	// This API *must* be called prior to analyzing these results.
	// Experimental.
	Finished() MatchResult
	// Does the result contain any failures.
	//
	// If not, the result is a success.
	// Experimental.
	HasFailed() *bool
	// DEPRECATED.
	// Deprecated: use recordFailure().
	Push(matcher Matcher, path *[]*string, message *string) MatchResult
	// Record a capture against in this match result.
	// Experimental.
	RecordCapture(options *MatchCapture)
	// Record a new failure into this result at a specific path.
	// Experimental.
	RecordFailure(failure *MatchFailure) MatchResult
	// Get the list of failures as human readable strings.
	// Experimental.
	ToHumanStrings() *[]*string
}

The result of `Match.test()`.

Example:

import awscdk "github.com/aws/aws-cdk-go/awscdk"import assertions "github.com/aws/aws-cdk-go/awscdk/assertions"

var target interface{}
matchResult := assertions.NewMatchResult(target)

Experimental.

func NewMatchResult

func NewMatchResult(target interface{}) MatchResult

Experimental.

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.
	// Experimental.
	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.
	// Experimental.
	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": ["Flob", "Cat"]
//       }
//     }
//   }
// }

// The following will NOT throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]matcher{
	"Fred": Match.arrayWith([]interface{}{
		jsii.String("Flob"),
	}),
})

// The following will throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), match.objectLike(map[string]interface{}{
	"Fred": match.arrayWith([]interface{}{
		jsii.String("Wobble"),
	}),
}))

Experimental.

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. Experimental.

func Match_AnyValue

func Match_AnyValue() Matcher

Matches any non-null value at the target. Experimental.

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. Experimental.

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. Experimental.

func Match_Exact

func Match_Exact(pattern interface{}) Matcher

Deep exact matching of the specified pattern to the target. Experimental.

func Match_Not

func Match_Not(pattern interface{}) Matcher

Matches any target which does NOT follow the specified pattern. Experimental.

func Match_ObjectEquals

func Match_ObjectEquals(pattern *map[string]interface{}) Matcher

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. Experimental.

func Match_ObjectLike

func Match_ObjectLike(pattern *map[string]interface{}) Matcher

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. Experimental.

func Match_SerializedJson

func Match_SerializedJson(pattern interface{}) Matcher

Matches any string-encoded JSON and applies the specified pattern after parsing it. Experimental.

func Match_StringLikeRegexp

func Match_StringLikeRegexp(pattern *string) Matcher

Matches targets according to a regular expression. Experimental.

type Template

type Template interface {
	// Get the set of matching Conditions that match the given properties in the CloudFormation template.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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.
	// Experimental.
	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 behavour, use other matchers in the `Match` class.
	// Experimental.
	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 behavour, use other matchers in the `Match` class.
	// Experimental.
	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 behavour, use other matchers in the `Match` class.
	// Experimental.
	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.
	// Experimental.
	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 behavour, use other matchers in the `Match` class.
	// Experimental.
	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 behavour, use other matchers in the `Match` class.
	// Experimental.
	HasResourceProperties(type_ *string, props interface{})
	// Assert that the given number of resources of the given type exist in the template.
	// Experimental.
	ResourceCountIs(type_ *string, count *float64)
	// Assert that the CloudFormation template matches the given value.
	// Experimental.
	TemplateMatches(expected interface{})
	// The CloudFormation template deserialized into an object.
	// Experimental.
	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 awscdk "github.com/aws/aws-cdk-go/awscdk"type Stack awscdk.Stackimport awscdk "github.com/aws/aws-cdk-go/awscdk"type Template awscdk.Template

stack := NewStack()
// ...
template := template.fromStack(stack)

Experimental.

func Template_FromJSON

func Template_FromJSON(template *map[string]interface{}) Template

Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object. Experimental.

func Template_FromStack

func Template_FromStack(stack awscdk.Stack) Template

Base your assertions on the CloudFormation template synthesized by a CDK `Stack`. Experimental.

func Template_FromString

func Template_FromString(template *string) Template

Base your assertions from an existing CloudFormation template formatted as a JSON string. Experimental.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL