assertions

package
v1.168.0-devpreview Latest Latest
Warning

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

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

README

Assertions

If you're migrating from the old assert library, the migration guide can be found in our GitHub repository.

Functions for writing test asserting against CDK applications, with focus on CloudFormation templates.

The Template class includes a set of methods for writing assertions against CloudFormation templates. Use one of the Template.fromXxx() static methods to create an instance of this class.

To create Template from CDK stack, start off with:

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

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

Alternatively, assertions can be run on an existing CloudFormation template -

templateJson := "{ \"Resources\": ... }" /* The CloudFormation template as JSON serialized string. */
template := awscdk.Template.fromString(templateJson)

Full Template Match

The simplest assertion would be to assert that the template matches a given template.

template.templateMatches(map[string]map[string]map[string]interface{}{
	"Resources": map[string]map[string]interface{}{
		"BarLogicalId": map[string]interface{}{
			"Type": jsii.String("Foo::Bar"),
			"Properties": map[string]*string{
				"Baz": jsii.String("Qux"),
			},
		},
	},
})

By default, the templateMatches() API will use the an 'object-like' comparison, which means that it will allow for the actual template to be a superset of the given expectation. See Special Matchers for details on how to change this.

Snapshot testing is a common technique to store a snapshot of the output and compare it during future changes. Since CloudFormation templates are human readable, they are a good target for snapshot testing.

The toJSON() method on the Template can be used to produce a well formatted JSON of the CloudFormation template that can be used as a snapshot.

See Snapshot Testing in Jest and Snapshot Testing in Java.

Counting Resources

This module allows asserting the number of resources of a specific type found in a template.

template.resourceCountIs(jsii.String("Foo::Bar"), jsii.Number(2))

Resource Matching & Retrieval

Beyond resource counting, the module also allows asserting that a resource with specific properties are present.

The following code asserts that the Properties section of a resource of type Foo::Bar contains the specified properties -

template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]interface{}{
	"Foo": jsii.String("Bar"),
	"Baz": jsii.Number(5),
	"Qux": []*string{
		jsii.String("Waldo"),
		jsii.String("Fred"),
	},
})

Alternatively, if you would like to assert the entire resource definition, you can use the hasResource() API.

template.hasResource(jsii.String("Foo::Bar"), map[string]interface{}{
	"Properties": map[string]*string{
		"Foo": jsii.String("Bar"),
	},
	"DependsOn": []*string{
		jsii.String("Waldo"),
		jsii.String("Fred"),
	},
})

Beyond assertions, the module provides APIs to retrieve matching resources. The findResources() API is complementary to the hasResource() API, except, instead of asserting its presence, it returns the set of matching resources.

By default, the hasResource() and hasResourceProperties() APIs perform deep partial object matching. This behavior can be configured using matchers. See subsequent section on special matchers.

Output and Mapping sections

The module allows you to assert that the CloudFormation template contains an Output that matches specific properties. The following code asserts that a template contains an Output with a logicalId of Foo and the specified properties -

expected := map[string]interface{}{
	"Value": jsii.String("Bar"),
	"Export": map[string]*string{
		"Name": jsii.String("ExportBaz"),
	},
}
template.hasOutput(jsii.String("Foo"), expected)

If you want to match against all Outputs in the template, use * as the logicalId.

template.hasOutput(jsii.String("*"), map[string]interface{}{
	"Value": jsii.String("Bar"),
	"Export": map[string]*string{
		"Name": jsii.String("ExportBaz"),
	},
})

findOutputs() will return a set of outputs that match the logicalId and props, and you can use the '*' special case as well.

result := template.findOutputs(jsii.String("*"), map[string]*string{
	"Value": jsii.String("Fred"),
})
expect(result.foo)_ToEqual(map[string]*string{
	"Value": jsii.String("Fred"),
	"Description": jsii.String("FooFred"),
})
expect(result.bar)_ToEqual(map[string]*string{
	"Value": jsii.String("Fred"),
	"Description": jsii.String("BarFred"),
})

The APIs hasMapping(), findMappings(), hasCondition(), and hasCondtions() provide similar functionalities.

Special Matchers

The expectation provided to the hasXxx(), findXxx() and templateMatches() APIs, besides carrying literal values, as seen in the above examples, also accept special matchers.

They are available as part of the Match class.

Object Matchers

The Match.objectLike() API can be used to assert that the target is a superset object of the provided pattern. This API will perform a deep partial match on the target. Deep partial matching is where objects are matched partially recursively. At each level, the list of keys in the target is a subset of the provided pattern.

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": {
//           "Wobble": "Flob",
//           "Bob": "Cat"
//         }
//       }
//     }
//   }
// }

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

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

The Match.objectEquals() API can be used to assert a target as a deep exact match.

Presence and Absence

The Match.absent() matcher can be used to specify that a specific value should not exist on the target. This can be used within Match.objectLike() or outside of any matchers.

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": {
//           "Wobble": "Flob",
//         }
//       }
//     }
//   }
// }

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

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

The Match.anyValue() matcher can be used to specify that a specific value should be found at the location. This matcher will fail if when the target location has null-ish values (i.e., null or undefined).

This matcher can be combined with any of the other matchers.

// 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(),
	},
})
Array Matchers

The Match.arrayWith() API can be used to assert that the target is equal to or a subset of the provided pattern array. This API will perform subset match on the target.

// 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": awscdk.Match.arrayWith([]interface{}{
		jsii.String("Flob"),
	}),
})

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

Note: The list of items in the pattern array should be in order as they appear in the target array. Out of order will be recorded as a match failure.

Alternatively, the Match.arrayEquals() API can be used to assert that the target is exactly equal to the pattern array.

String Matchers

The Match.stringLikeRegexp() API can be used to assert that the target matches the provided regular expression.

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Template": "const includeHeaders = true;"
//       }
//     }
//   }
// }

// The following will NOT throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]matcher{
	"Template": awscdk.Match.stringLikeRegexp(jsii.String("includeHeaders = (true|false)")),
})

// The following will throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]matcher{
	"Template": awscdk.Match.stringLikeRegexp(jsii.String("includeHeaders = null")),
})
Not Matcher

The not matcher inverts the search pattern and matches all patterns in the path that does not match the pattern specified.

// 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": awscdk.Match.not([]interface{}{
		jsii.String("Flob"),
	}),
})

// The following will throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), awscdk.Match.objectLike(map[string]interface{}{
	"Fred": awscdk.Match.not([]interface{}{
		jsii.String("Flob"),
		jsii.String("Cat"),
	}),
}))
Serialized JSON

Often, we find that some CloudFormation Resource types declare properties as a string, but actually expect JSON serialized as a string. For example, the BuildSpec property of AWS::CodeBuild::Project, the Definition property of AWS::StepFunctions::StateMachine, to name a couple.

The Match.serializedJson() matcher allows deep matching within a stringified JSON.

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Baz": "{ \"Fred\": [\"Waldo\", \"Willow\"] }"
//       }
//     }
//   }
// }

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

// The following will throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]matcher{
	"Baz": awscdk.Match.serializedJson(map[string][]*string{
		"Fred": []*string{
			jsii.String("Waldo"),
			jsii.String("Johnny"),
		},
	}),
})

Capturing Values

The matcher APIs documented above allow capturing values in the matching entry (Resource, Output, Mapping, etc.). The following code captures a string from a matching resource.

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": ["Flob", "Cat"],
//         "Waldo": ["Qix", "Qux"],
//       }
//     }
//   }
// }

fredCapture := awscdk.NewCapture()
waldoCapture := awscdk.NewCapture()
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]interface{}{
	"Fred": fredCapture,
	"Waldo": []interface{}{
		jsii.String("Qix"),
		waldoCapture,
	},
})

fredCapture.asArray() // returns ["Flob", "Cat"]
waldoCapture.asString()

With captures, a nested pattern can also be specified, so that only targets that match the nested pattern will be captured. This pattern can be literals or further Matchers.

// Given a template -
// {
//   "Resources": {
//     "MyBar1": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": ["Flob", "Cat"],
//       }
//     }
//     "MyBar2": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": ["Qix", "Qux"],
//       }
//     }
//   }
// }

capture := awscdk.NewCapture(awscdk.Match.arrayWith([]interface{}{
	jsii.String("Cat"),
}))
template.hasResourceProperties(jsii.String("Foo::Bar"), map[string]capture{
	"Fred": capture,
})

capture.asArray()

When multiple resources match the given condition, each Capture defined in the condition will capture all matching values. They can be paged through using the next() API. The following example illustrates this -

// 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()

Asserting Annotations

In addition to template matching, we provide an API for annotation matching. Annotations can be added via the Aspects API. You can learn more about Aspects here.

Say you have a MyAspect and a MyStack that uses MyAspect:

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

type myAspect struct {
}

func (this *myAspect) visit(node iConstruct) {
	if *node instanceof cdk.cfnResource && *node.cfnResourceType == "Foo::Bar" {
		this.error(*node, jsii.String("we do not want a Foo::Bar resource"))
	}
}

func (this *myAspect) error(node iConstruct, message *string) {
	cdk.annotations.of(*node).addError(*message)
}

type myStack struct {
	stack
}

func newMyStack(scope construct, id *string) *myStack {
	this := &myStack{}
	cdk.NewStack_Override(this, scope, id)

	stack := cdk.NewStack()
	cdk.NewCfnResource(stack, jsii.String("Foo"), &cfnResourceProps{
		type: jsii.String("Foo::Bar"),
		properties: map[string]interface{}{
			"Fred": jsii.String("Thud"),
		},
	})
	cdk.aspects.of(stack).add(NewMyAspect())
	return this
}

We can then assert that the stack contains the expected Error:

// import { Annotations } from '@aws-cdk/assertions';

awscdk.Annotations.fromStack(stack).hasError(jsii.String("/Default/Foo"), jsii.String("we do not want a Foo::Bar resource"))

Here are the available APIs for Annotations:

  • hasError(), hasNoError(), and findError()
  • hasWarning(), hasNoWarning(), and findWarning()
  • hasInfo(), hasNoInfo(), and findInfo()

The corresponding findXxx() API is complementary to the hasXxx() API, except instead of asserting its presence, it returns the set of matching messages.

In addition, this suite of APIs is compatable with Matchers for more fine-grained control. For example, the following assertion works as well:

awscdk.Annotations.fromStack(stack).hasError(jsii.String("/Default/Foo"), awscdk.Match.stringLikeRegexp(jsii.String(".*Foo::Bar.*")))

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:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import monocdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var stack stack

annotations := awscdk.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 := awscdk.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 `field:"required" json:"capture" yaml:"capture"`
	// The value that was captured.
	// Experimental.
	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,
}

Experimental.

type MatchFailure

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

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"),
	},
}

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:

// 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)

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": awscdk.Match.arrayWith([]interface{}{
		jsii.String("Flob"),
	}),
})

// The following will throw an assertion error
template.hasResourceProperties(jsii.String("Foo::Bar"), awscdk.Match.objectLike(map[string]interface{}{
	"Fred": awscdk.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 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

stack := awscdk.NewStack()
// ...
template := awscdk.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