ExpectedResult

class aws_cdk.integ_tests_alpha.ExpectedResult

Bases: object

(experimental) Represents the “expected” results to compare.

Stability:

experimental

ExampleMetadata:

infused

Example:

# app: App
# integ: IntegTest

integ.assertions.aws_api_call("SQS", "sendMessage", {
    "QueueUrl": "url",
    "MessageBody": "hello"
})
message = integ.assertions.aws_api_call("SQS", "receiveMessage", {
    "QueueUrl": "url"
})
message.expect(ExpectedResult.object_like({
    "Messages": [{"Body": "hello"}]
}))
Stability:

experimental

Attributes

result

(experimental) The expected results encoded as a string.

Stability:

experimental

Static Methods

classmethod array_with(expected)

(experimental) The actual results must be a list and must contain an item with the expected results.

Parameters:

expected (Sequence[Any]) –

See:

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-arraywbrwithpattern

Stability:

experimental

Return type:

ExpectedResult

Example:

# actual results
actual = [{
    "string_param": "hello"
}, {
    "string_param": "world"
}
]
# pass
ExpectedResult.array_with([{
    "string_param": "hello"
}
])
classmethod exact(expected)

(experimental) The actual results must match exactly.

Missing data will result in a failure

Parameters:

expected (Any) –

See:

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-exactpattern

Stability:

experimental

Return type:

ExpectedResult

Example:

# actual results
actual = {
    "string_param": "hello",
    "number_param": 3,
    "boolean_param": True
}
# pass
ExpectedResult.exact({
    "string_param": "hello",
    "number_param": 3,
    "boolean_param": True
})

# fail
ExpectedResult.exact({
    "string_param": "hello"
})
classmethod object_like(expected)

(experimental) The expected results must be a subset of the actual results.

Parameters:

expected (Mapping[str, Any]) –

See:

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-objectwbrlikepattern

Stability:

experimental

Return type:

ExpectedResult

Example:

# actual results
actual = {
    "string_param": "hello",
    "number_param": 3,
    "boolean_param": True,
    "object_param": {"prop1": "value", "prop2": "value"}
}
# pass
ExpectedResult.object_like({
    "string_param": "hello",
    "object_param": {"prop1": "value"}
})
classmethod string_like_regexp(expected)

(experimental) Actual results is a string that matches the Expected result regex.

Parameters:

expected (str) –

See:

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-stringwbrlikewbrregexppattern

Stability:

experimental

Return type:

ExpectedResult

Example:

# actual results
actual = "some string value"

# pass
ExpectedResult.string_like_regexp("value")