Skip to content
v2.276.0

Experimental

@aws-cdk/integ-tests-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

ExpectedResult Class ​

Represents the "expected" results to compare.

Example ​

ts
declare const app: App;
declare const stack: Stack;
declare const sm: IStateMachine;

const testCase = new IntegTest(app, 'IntegTest', {
  testCases: [stack],
});

// Start an execution
const start = testCase.assertions.awsApiCall('StepFunctions', 'startExecution', {
  stateMachineArn: sm.stateMachineArn,
});

// describe the results of the execution
const describe = testCase.assertions.awsApiCall('StepFunctions', 'describeExecution', {
  executionArn: start.getAttString('executionArn'),
});

// assert the results
describe.expect(ExpectedResult.objectLike({
  status: 'SUCCEEDED',
}));
python
# app: App
# stack: Stack
# sm: IStateMachine


test_case = IntegTest(app, "IntegTest",
    test_cases=[stack]
)

# Start an execution
start = test_case.assertions.aws_api_call("StepFunctions", "startExecution", {
    "state_machine_arn": sm.state_machine_arn
})

# describe the results of the execution
describe = test_case.assertions.aws_api_call("StepFunctions", "describeExecution", {
    "execution_arn": start.get_att_string("executionArn")
})

# assert the results
describe.expect(ExpectedResult.object_like({
    "status": "SUCCEEDED"
}))
java
App app;
Stack stack;
IStateMachine sm;


IntegTest testCase = IntegTest.Builder.create(app, "IntegTest")
        .testCases(List.of(stack))
        .build();

// Start an execution
IApiCall start = testCase.assertions.awsApiCall("StepFunctions", "startExecution", Map.of(
        "stateMachineArn", sm.getStateMachineArn()));

// describe the results of the execution
IApiCall describe = testCase.assertions.awsApiCall("StepFunctions", "describeExecution", Map.of(
        "executionArn", start.getAttString("executionArn")));

// assert the results
describe.expect(ExpectedResult.objectLike(Map.of(
        "status", "SUCCEEDED")));
csharp
// Install: dotnet add package Amazon.CDK.IntegTests.Alpha
App app;
Stack stack;
IStateMachine sm;


var testCase = new IntegTest(app, "IntegTest", new IntegTestProps {
    TestCases = new [] { stack }
});

// Start an execution
var start = testCase.Assertions.AwsApiCall("StepFunctions", "startExecution", new Dictionary<string, string> {
    { "stateMachineArn", sm.StateMachineArn }
});

// describe the results of the execution
var describe = testCase.Assertions.AwsApiCall("StepFunctions", "describeExecution", new Dictionary<string, string> {
    { "executionArn", start.GetAttString("executionArn") }
});

// assert the results
describe.Expect(ExpectedResult.ObjectLike(new Dictionary<string, object> {
    { "status", "SUCCEEDED" }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdkintegtestsalpha/v2
var app App
var stack Stack
var sm IStateMachine


testCase := awscdkintegtestsalpha.NewIntegTest(app, jsii.String("IntegTest"), &IntegTestProps{
	TestCases: []Stack{
		stack,
	},
})

// Start an execution
start := testCase.Assertions.AwsApiCall(jsii.String("StepFunctions"), jsii.String("startExecution"), map[string]*string{
	"stateMachineArn": sm.stateMachineArn,
})

// describe the results of the execution
describe := testCase.Assertions.AwsApiCall(jsii.String("StepFunctions"), jsii.String("describeExecution"), map[string]*string{
	"executionArn": start.getAttString(jsii.String("executionArn")),
})

// assert the results
describe.Expect(awscdkintegtestsalpha.ExpectedResult_ObjectLike(map[string]interface{}{
	"status": jsii.String("SUCCEEDED"),
}))

Initializer ​

ts
new ExpectedResult()
python
ExpectedResult()
java
new ExpectedResult()
csharp
new ExpectedResult()
go
NewExpectedResult()

Properties ​

resultstringresultstrresultStringResultstringResult*string#
The expected results encoded as a string.

Methods ​

arrayWith(expected: any[]): ExpectedResult // chainable@staticmethod def array_with(expected: typing.List[Any]) -> ExpectedResultpublic static ExpectedResult arrayWith(List<Object> expected)public static ExpectedResult ArrayWith(object[] expected)func ArrayWith(Expected *[]interface{}) ExpectedResultstatic#
The actual results must be a list and must contain an item with the expected results.
example
ts
// actual results
const actual = [
  {
    stringParam: 'hello',
  },
  {
    stringParam: 'world',
  },
];
// pass
ExpectedResult.arrayWith([
  {
    stringParam: 'hello',
  },
]);
exact(expected: any): ExpectedResult // chainable@staticmethod def exact(expected: Any) -> ExpectedResultpublic static ExpectedResult exact(Object expected)public static ExpectedResult Exact(object expected)func Exact(Expected interface{}) ExpectedResultstatic#
The actual results must match exactly.

Missing data will result in a failure

example
ts
// actual results
const actual = {
  stringParam: 'hello',
  numberParam: 3,
  booleanParam: true,
};
// pass
ExpectedResult.exact({
  stringParam: 'hello',
  numberParam: 3,
  booleanParam: true,
})

// fail
ExpectedResult.exact({
  stringParam: 'hello',
});
objectLike(expected: { [key: string]: any }): ExpectedResult // chainable@staticmethod def object_like(expected: typing.Mapping[str, Any]) -> ExpectedResultpublic static ExpectedResult objectLike(Map<String, Object> expected)public static ExpectedResult ObjectLike(IDictionary<string, object> expected)func ObjectLike(Expected *map[string]interface{}) ExpectedResultstatic#
The expected results must be a subset of the actual results.
example
ts
// actual results
const actual = {
  stringParam: 'hello',
  numberParam: 3,
  booleanParam: true,
  objectParam: { prop1: 'value', prop2: 'value' },
};
// pass
ExpectedResult.objectLike({
  stringParam: 'hello',
  objectParam: { prop1: 'value' },
});
stringLikeRegexp(expected: string): ExpectedResult // chainable@staticmethod def string_like_regexp(expected: str) -> ExpectedResultpublic static ExpectedResult stringLikeRegexp(String expected)public static ExpectedResult StringLikeRegexp(string expected)func StringLikeRegexp(Expected *string) ExpectedResultstatic#
Actual results is a string that matches the Expected result regex.
example
ts
// actual results
const actual = 'some string value';

// pass
ExpectedResult.stringLikeRegexp('value');