Matcher Class
Represents a matcher that can perform special data matching capabilities between a given pattern and a target.
Example
ts
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": {
// "Wobble": ["Flob", "Flib"],
// }
// }
// }
// }
// }
// The following will NOT throw an assertion error
template.hasResourceProperties('Foo::Bar', {
Fred: {
Wobble: [ Match.anyValue(), Match.anyValue() ],
},
});
// The following will throw an assertion error
template.hasResourceProperties('Foo::Bar', {
Fred: {
Wimble: Match.anyValue(),
},
});
python
# Given a template -
# {
# "Resources": {
# "MyBar": {
# "Type": "Foo::Bar",
# "Properties": {
# "Fred": {
# "Wobble": ["Flob", "Flib"],
# }
# }
# }
# }
# }
# The following will NOT throw an assertion error
template.has_resource_properties("Foo::Bar", {
"Fred": {
"Wobble": [Match.any_value(), Match.any_value()]
}
})
# The following will throw an assertion error
template.has_resource_properties("Foo::Bar", {
"Fred": {
"Wimble": Match.any_value()
}
})
java
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": {
// "Wobble": ["Flob", "Flib"],
// }
// }
// }
// }
// }
// The following will NOT throw an assertion error
template.hasResourceProperties("Foo::Bar", Map.of(
"Fred", Map.of(
"Wobble", List.of(Match.anyValue(), Match.anyValue()))));
// The following will throw an assertion error
template.hasResourceProperties("Foo::Bar", Map.of(
"Fred", Map.of(
"Wimble", Match.anyValue())));
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": {
// "Wobble": ["Flob", "Flib"],
// }
// }
// }
// }
// }
// The following will NOT throw an assertion error
template.HasResourceProperties("Foo::Bar", new Dictionary<string, IDictionary<string, Matcher[]>> {
{ "Fred", new Struct {
Wobble = new [] { Match.AnyValue(), Match.AnyValue() }
} }
});
// The following will throw an assertion error
template.HasResourceProperties("Foo::Bar", new Dictionary<string, IDictionary<string, Matcher>> {
{ "Fred", new Struct {
Wimble = Match.AnyValue()
} }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// 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(),
},
})
Initializer
ts
new Matcher()
python
Matcher()
java
new Matcher()
csharp
new Matcher()
go
NewMatcher()
Properties
A name for the matcher.
This is collected as part of the result and may be presented to the user.
Methods
isMatcher(x: any): boolean@staticmethod def is_matcher(x: Any) -> boolpublic static Boolean isMatcher(Object x)public static bool IsMatcher(object x)func IsMatcher(X interface{}) *boolstatic#Check whether the provided object is a subtype of the `IMatcher`.
test(actual: any): MatchResultdef test(self, actual: Any) -> MatchResultpublic MatchResult test(Object actual)public MatchResult Test(object actual)func Test(Actual interface{}) MatchResult#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.
1 parameter · returns
Parameters
actualactualactualactualActual— the target to match.
Returns: the list of match failures. An empty array denotes a successful match.