Skip to content

Commit 1b18be7

Browse files
author
awstools
committed
feat(client-sfn): Adds support to TestState for mocked results and exceptions, along with additional inspection data.
1 parent b77d168 commit 1b18be7

File tree

5 files changed

+602
-12
lines changed

5 files changed

+602
-12
lines changed

clients/client-sfn/src/commands/TestStateCommand.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface TestStateCommandOutput extends TestStateOutput, __MetadataBeare
7575
* <p>The <code>TestState</code> API assumes an IAM role which must contain the required IAM permissions for the resources your state is accessing. For information about the permissions a state might need, see <a href="https://docs.aws.amazon.com/step-functions/latest/dg/test-state-isolation.html#test-state-permissions">IAM permissions to test a state</a>.</p>
7676
* <p>The <code>TestState</code> API can run for up to five minutes. If the execution of a state exceeds this duration, it fails with the <code>States.Timeout</code> error.</p>
7777
* <p>
78-
* <code>TestState</code> doesn't support <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html">Activity tasks</a>, <code>.sync</code> or <code>.waitForTaskToken</code>
78+
* <code>TestState</code> only supports the following when a mock is specified: <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html">Activity tasks</a>, <code>.sync</code> or <code>.waitForTaskToken</code>
7979
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html">service integration patterns</a>, <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-parallel-state.html">Parallel</a>, or <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html">Map</a> states.</p>
8080
* @example
8181
* Use a bare-bones client and the command you need to make an API call.
@@ -92,6 +92,22 @@ export interface TestStateCommandOutput extends TestStateOutput, __MetadataBeare
9292
* inspectionLevel: "INFO" || "DEBUG" || "TRACE",
9393
* revealSecrets: true || false,
9494
* variables: "STRING_VALUE",
95+
* stateName: "STRING_VALUE",
96+
* mock: { // MockInput
97+
* result: "STRING_VALUE",
98+
* errorOutput: { // MockErrorOutput
99+
* error: "STRING_VALUE",
100+
* cause: "STRING_VALUE",
101+
* },
102+
* fieldValidationMode: "STRICT" || "PRESENT" || "NONE",
103+
* },
104+
* context: "STRING_VALUE",
105+
* stateConfiguration: { // TestStateConfiguration
106+
* retrierRetryCount: Number("int"),
107+
* errorCausedByState: "STRING_VALUE",
108+
* mapIterationFailureCount: Number("int"),
109+
* mapItemReaderData: "STRING_VALUE",
110+
* },
95111
* };
96112
* const command = new TestStateCommand(input);
97113
* const response = await client.send(command);
@@ -122,6 +138,18 @@ export interface TestStateCommandOutput extends TestStateOutput, __MetadataBeare
122138
* // body: "STRING_VALUE",
123139
* // },
124140
* // variables: "STRING_VALUE",
141+
* // errorDetails: { // InspectionErrorDetails
142+
* // catchIndex: Number("int"),
143+
* // retryIndex: Number("int"),
144+
* // retryBackoffIntervalSeconds: Number("int"),
145+
* // },
146+
* // afterItemsPath: "STRING_VALUE",
147+
* // afterItemSelector: "STRING_VALUE",
148+
* // afterItemBatcher: "STRING_VALUE",
149+
* // afterItemsPointer: "STRING_VALUE",
150+
* // toleratedFailureCount: Number("int"),
151+
* // toleratedFailurePercentage: Number("float"),
152+
* // maxConcurrency: Number("int"),
125153
* // },
126154
* // nextState: "STRING_VALUE",
127155
* // status: "SUCCEEDED" || "FAILED" || "RETRIABLE" || "CAUGHT_ERROR",

clients/client-sfn/src/models/enums.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ export const InspectionLevel = {
257257
*/
258258
export type InspectionLevel = (typeof InspectionLevel)[keyof typeof InspectionLevel];
259259

260+
/**
261+
* @public
262+
* @enum
263+
*/
264+
export const MockResponseValidationMode = {
265+
NONE: "NONE",
266+
PRESENT: "PRESENT",
267+
STRICT: "STRICT",
268+
} as const;
269+
/**
270+
* @public
271+
*/
272+
export type MockResponseValidationMode = (typeof MockResponseValidationMode)[keyof typeof MockResponseValidationMode];
273+
260274
/**
261275
* @public
262276
* @enum

clients/client-sfn/src/models/models_0.ts

Lines changed: 187 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
InspectionLevel,
1010
LogLevel,
1111
MapRunStatus,
12+
MockResponseValidationMode,
1213
StateMachineStatus,
1314
StateMachineType,
1415
SyncExecutionStatus,
@@ -2297,7 +2298,7 @@ export interface TaskTimedOutEventDetails {
22972298
*/
22982299
export interface HistoryEvent {
22992300
/**
2300-
* <p>The date and time the event occurred.</p>
2301+
* <p>The date and time the event occurred, expressed in seconds and fractional milliseconds since the Unix epoch, which is defined as January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC).</p>
23012302
* @public
23022303
*/
23032304
timestamp: Date | undefined;
@@ -3597,12 +3598,99 @@ export interface TagResourceInput {
35973598
*/
35983599
export interface TagResourceOutput {}
35993600

3601+
/**
3602+
* <p>A JSON object that contains a mocked error.</p>
3603+
* @public
3604+
*/
3605+
export interface MockErrorOutput {
3606+
/**
3607+
* <p>A string denoting the error code of the exception thrown when invoking the tested state. This field is required if <code>mock.errorOutput</code> is specified.</p>
3608+
* @public
3609+
*/
3610+
error?: string | undefined;
3611+
3612+
/**
3613+
* <p>A string containing the cause of the exception thrown when executing the state's logic.</p>
3614+
* @public
3615+
*/
3616+
cause?: string | undefined;
3617+
}
3618+
3619+
/**
3620+
* <p>A JSON object that contains a mocked <code>result</code> or <code>errorOutput</code>.</p>
3621+
* @public
3622+
*/
3623+
export interface MockInput {
3624+
/**
3625+
* <p>A JSON string containing the mocked result of the state invocation.</p>
3626+
* @public
3627+
*/
3628+
result?: string | undefined;
3629+
3630+
/**
3631+
* <p>The mocked error output when calling TestState. When specified, the mocked response is returned as a JSON object that contains an <code>error</code> and <code>cause</code> field.</p>
3632+
* @public
3633+
*/
3634+
errorOutput?: MockErrorOutput | undefined;
3635+
3636+
/**
3637+
* <p>Determines the level of strictness when validating mocked results against their respective API models. Values include:</p>
3638+
* <ul>
3639+
* <li>
3640+
* <p>
3641+
* <code>STRICT</code>: All required fields must be present, and all present fields must conform to the API's schema.</p>
3642+
* </li>
3643+
* <li>
3644+
* <p>
3645+
* <code>PRESENT</code>: All present fields must conform to the API's schema.</p>
3646+
* </li>
3647+
* <li>
3648+
* <p>
3649+
* <code>NONE</code>: No validation is performed.</p>
3650+
* </li>
3651+
* </ul>
3652+
* <p>If no value is specified, the default value is <code>STRICT</code>.</p>
3653+
* @public
3654+
*/
3655+
fieldValidationMode?: MockResponseValidationMode | undefined;
3656+
}
3657+
3658+
/**
3659+
* <p>Contains configurations for the tested state.</p>
3660+
* @public
3661+
*/
3662+
export interface TestStateConfiguration {
3663+
/**
3664+
* <p>The number of retry attempts that have occurred for the state's Retry that applies to the mocked error.</p>
3665+
* @public
3666+
*/
3667+
retrierRetryCount?: number | undefined;
3668+
3669+
/**
3670+
* <p>The name of the state from which an error originates when an error is mocked for a Map or Parallel state.</p>
3671+
* @public
3672+
*/
3673+
errorCausedByState?: string | undefined;
3674+
3675+
/**
3676+
* <p>The number of Map state iterations that failed during the Map state invocation.</p>
3677+
* @public
3678+
*/
3679+
mapIterationFailureCount?: number | undefined;
3680+
3681+
/**
3682+
* <p>The data read by ItemReader in Distributed Map states as found in its original source.</p>
3683+
* @public
3684+
*/
3685+
mapItemReaderData?: string | undefined;
3686+
}
3687+
36003688
/**
36013689
* @public
36023690
*/
36033691
export interface TestStateInput {
36043692
/**
3605-
* <p>The <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html">Amazon States Language</a> (ASL) definition of the state.</p>
3693+
* <p>The <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html">Amazon States Language</a> (ASL) definition of the state or state machine.</p>
36063694
* @public
36073695
*/
36083696
definition: string | undefined;
@@ -3653,6 +3741,55 @@ export interface TestStateInput {
36533741
* @public
36543742
*/
36553743
variables?: string | undefined;
3744+
3745+
/**
3746+
* <p>Denotes the particular state within a state machine definition to be tested. If this field is specified, the <code>definition</code> must contain a fully-formed state machine definition.</p>
3747+
* @public
3748+
*/
3749+
stateName?: string | undefined;
3750+
3751+
/**
3752+
* <p>Defines a mocked result or error for the state under test.</p>
3753+
* <p>A mock can only be specified for Task, Map, or Parallel states. If it is specified for another state type, an exception will be thrown.</p>
3754+
* @public
3755+
*/
3756+
mock?: MockInput | undefined;
3757+
3758+
/**
3759+
* <p>A JSON string representing a valid Context object for the state under test. This field may only be specified if a mock is specified in the same request.</p>
3760+
* @public
3761+
*/
3762+
context?: string | undefined;
3763+
3764+
/**
3765+
* <p>Contains configurations for the state under test.</p>
3766+
* @public
3767+
*/
3768+
stateConfiguration?: TestStateConfiguration | undefined;
3769+
}
3770+
3771+
/**
3772+
* <p>An object containing data about a handled exception in the tested state.</p>
3773+
* @public
3774+
*/
3775+
export interface InspectionErrorDetails {
3776+
/**
3777+
* <p>The array index of the Catch which handled the exception.</p>
3778+
* @public
3779+
*/
3780+
catchIndex?: number | undefined;
3781+
3782+
/**
3783+
* <p>The array index of the Retry which handled the exception.</p>
3784+
* @public
3785+
*/
3786+
retryIndex?: number | undefined;
3787+
3788+
/**
3789+
* <p>The duration in seconds of the backoff for a retry on a failed state invocation.</p>
3790+
* @public
3791+
*/
3792+
retryBackoffIntervalSeconds?: number | undefined;
36563793
}
36573794

36583795
/**
@@ -3791,6 +3928,54 @@ export interface InspectionData {
37913928
* @public
37923929
*/
37933930
variables?: string | undefined;
3931+
3932+
/**
3933+
* <p>An object containing data about a handled exception in the tested state.</p>
3934+
* @public
3935+
*/
3936+
errorDetails?: InspectionErrorDetails | undefined;
3937+
3938+
/**
3939+
* <p>The effective input after the ItemsPath filter is applied. Not populated when the QueryLanguage is JSONata.</p>
3940+
* @public
3941+
*/
3942+
afterItemsPath?: string | undefined;
3943+
3944+
/**
3945+
* <p>An array containing the inputs for each Map iteration, transformed by the ItemSelector specified in a Map state.</p>
3946+
* @public
3947+
*/
3948+
afterItemSelector?: string | undefined;
3949+
3950+
/**
3951+
* <p>The effective input after the ItemBatcher filter is applied in a Map state.</p>
3952+
* @public
3953+
*/
3954+
afterItemBatcher?: string | undefined;
3955+
3956+
/**
3957+
* <p>The effective input after the ItemsPointer filter is applied in a Map state.</p>
3958+
* @public
3959+
*/
3960+
afterItemsPointer?: string | undefined;
3961+
3962+
/**
3963+
* <p>The tolerated failure threshold for a Map state as defined in number of Map state iterations.</p>
3964+
* @public
3965+
*/
3966+
toleratedFailureCount?: number | undefined;
3967+
3968+
/**
3969+
* <p>The tolerated failure threshold for a Map state as defined in percentage of Map state iterations.</p>
3970+
* @public
3971+
*/
3972+
toleratedFailurePercentage?: number | undefined;
3973+
3974+
/**
3975+
* <p>The max concurrency of the Map state.</p>
3976+
* @public
3977+
*/
3978+
maxConcurrency?: number | undefined;
37943979
}
37953980

37963981
/**

0 commit comments

Comments
 (0)