Skip to content

Commit 330df33

Browse files
committed
add contract tests for StepFunctions
1 parent 7de527e commit 330df33

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

test/contract-tests/images/applications/TestSimpleApp.AWSSDK.Core/Program.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Amazon.SecretsManager;
99
using Amazon.SimpleNotificationService;
1010
using Amazon.SQS;
11+
using Amazon.StepFunctions;
1112
using TestSimpleApp.AWSSDK.Core;
1213

1314
var builder = WebApplication.CreateBuilder(args);
@@ -24,6 +25,7 @@
2425
.AddSingleton<IAmazonKinesis>(provider => new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
2526
.AddSingleton<IAmazonSecretsManager>(provider => new AmazonSecretsManagerClient(new AmazonSecretsManagerConfig { ServiceURL = "http://localstack:4566" }))
2627
.AddSingleton<IAmazonSimpleNotificationService>(provider => new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
28+
.AddSingleton<IAmazonStepFunctions>(provider => new AmazonStepFunctionsClient(new AmazonStepFunctionsConfig { ServiceURL = "http://localstack:4566" }))
2729
// Bedrock services are not supported by localstack, so we mock the API responses on the aws-application-signals-tests-testsimpleapp server.
2830
.AddSingleton<IAmazonBedrock>(provider => new AmazonBedrockClient(new AmazonBedrockConfig { ServiceURL = "http://localhost:8080" }))
2931
.AddSingleton<IAmazonBedrockRuntime>(provider => new AmazonBedrockRuntimeClient(new AmazonBedrockRuntimeConfig { ServiceURL = "http://localhost:8080" }))
@@ -36,19 +38,22 @@
3638
.AddKeyedSingleton<IAmazonKinesis>("fault-kinesis", new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
3739
.AddKeyedSingleton<IAmazonSecretsManager>("fault-secretsmanager", new AmazonSecretsManagerClient(new AmazonSecretsManagerConfig { ServiceURL = "http://localstack:4566" }))
3840
.AddKeyedSingleton<IAmazonSimpleNotificationService>("fault-sns", new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
41+
.AddKeyedSingleton<IAmazonStepFunctions>("fault-stepfunctions", new AmazonStepFunctionsClient(new AmazonStepFunctionsConfig { ServiceURL = "http://localstack:4566" }))
3942
//error client
4043
.AddKeyedSingleton<IAmazonDynamoDB>("error-ddb", new AmazonDynamoDBClient(AmazonClientConfigHelper.CreateConfig<AmazonDynamoDBConfig>()))
4144
.AddKeyedSingleton<IAmazonS3>("error-s3", new AmazonS3Client(AmazonClientConfigHelper.CreateConfig<AmazonS3Config>()))
4245
.AddKeyedSingleton<IAmazonSQS>("error-sqs", new AmazonSQSClient(AmazonClientConfigHelper.CreateConfig<AmazonSQSConfig>()))
4346
.AddKeyedSingleton<IAmazonKinesis>("error-kinesis", new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
4447
.AddKeyedSingleton<IAmazonSecretsManager>("error-secretsmanager", new AmazonSecretsManagerClient(new AmazonSecretsManagerConfig {ServiceURL = "http://localstack:4566" }))
4548
.AddKeyedSingleton<IAmazonSimpleNotificationService>("error-sns", new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
49+
.AddKeyedSingleton<IAmazonStepFunctions>("error-stepfunctions", new AmazonStepFunctionsClient(new AmazonStepFunctionsConfig { ServiceURL = "http://localstack:4566" }))
4650
.AddSingleton<S3Tests>()
4751
.AddSingleton<DynamoDBTests>()
4852
.AddSingleton<SQSTests>()
4953
.AddSingleton<KinesisTests>()
5054
.AddSingleton<SecretsManagerTests>()
5155
.AddSingleton<SNSTests>()
56+
.AddSingleton<StepFunctionsTests>()
5257
.AddSingleton<BedrockTests>();
5358

5459
var app = builder.Build();
@@ -153,6 +158,25 @@
153158
app.MapGet("sns/fault", (SNSTests sns) => sns.Fault()).WithName("sns-fault").WithOpenApi();
154159
app.MapGet("sns/error", (SNSTests sns) => sns.Error()).WithName("sns-error").WithOpenApi();
155160

161+
app.MapGet("stepfunctions/createstatemachine/some-state-machine", (StepFunctionsTests stepFunctions) => stepFunctions.CreateStateMachine())
162+
.WithName("create-state-machine")
163+
.WithOpenApi();
164+
165+
app.MapGet("stepfunctions/describestatemachine/some-state-machine", (StepFunctionsTests stepFunctions) => stepFunctions.DescribeStateMachine())
166+
.WithName("describe-state-machine")
167+
.WithOpenApi();
168+
169+
app.MapGet("stepfunctions/createactivity/some-activity", (StepFunctionsTests stepFunctions) => stepFunctions.CreateActivity())
170+
.WithName("create-activity")
171+
.WithOpenApi();
172+
173+
app.MapGet("stepfunctions/describeactivity/some-activity", (StepFunctionsTests stepFunctions) => stepFunctions.DescribeActivity())
174+
.WithName("describe-activity")
175+
.WithOpenApi();
176+
177+
app.MapGet("stepfunctions/fault", (StepFunctionsTests stepFunctions) => stepFunctions.Fault()).WithName("stepfunctions-fault").WithOpenApi();
178+
app.MapGet("stepfunctions/error", (StepFunctionsTests stepFunctions) => stepFunctions.Error()).WithName("stepfunctions-error").WithOpenApi();
179+
156180
app.MapGet("bedrock/getguardrail/get-guardrail", (BedrockTests bedrock) => bedrock.GetGuardrail())
157181
.WithName("get-guardrail")
158182
.WithOpenApi();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Amazon.StepFunctions;
2+
using Amazon.StepFunctions.Model;
3+
4+
namespace TestSimpleApp.AWSSDK.Core;
5+
6+
public class StepFunctionsTests(
7+
IAmazonStepFunctions stepFunctions,
8+
[FromKeyedServices("fault-stepfunctions")] IAmazonStepFunctions faultClient,
9+
[FromKeyedServices("error-stepfunctions")] IAmazonStepFunctions errorClient,
10+
ILogger<StepFunctionsTests> logger) : ContractTest(logger)
11+
{
12+
public Task<CreateStateMachineResponse> CreateStateMachine()
13+
{
14+
return stepFunctions.CreateStateMachineAsync(new CreateStateMachineRequest
15+
{
16+
Name = "test-state-machine",
17+
Definition = "{\"StartAt\":\"TestState\",\"States\":{\"TestState\":{\"Type\":\"Pass\",\"End\":true,\"Result\":\"Result\"}}}",
18+
RoleArn = "arn:aws:iam::000000000000:role/stepfunctions-role"
19+
});
20+
}
21+
22+
public Task<DescribeStateMachineResponse> DescribeStateMachine()
23+
{
24+
return stepFunctions.DescribeStateMachineAsync(new DescribeStateMachineRequest { StateMachineArn = "arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine" });
25+
}
26+
27+
public Task<CreateActivityResponse> CreateActivity()
28+
{
29+
return stepFunctions.CreateActivityAsync(new CreateActivityRequest { Name = "test-activity" });
30+
}
31+
32+
public Task<DescribeActivityResponse> DescribeActivity()
33+
{
34+
return stepFunctions.DescribeActivityAsync(new DescribeActivityRequest { ActivityArn = "arn:aws:states:us-east-1:000000000000:activity:test-activity" });
35+
}
36+
37+
protected override Task CreateFault(CancellationToken cancellationToken)
38+
{
39+
return faultClient.CreateStateMachineAsync(new CreateStateMachineRequest
40+
{
41+
Name = "test-state-machine",
42+
Definition = "{\"StartAt\":\"TestState\",\"States\":{\"TestState\":{\"Type\":\"Pass\",\"End\":true,\"Result\":\"Result\"}}}",
43+
RoleArn = "arn:aws:iam::000000000000:role/stepfunctions-role"
44+
}, cancellationToken);
45+
}
46+
47+
protected override Task CreateError(CancellationToken cancellationToken)
48+
{
49+
return errorClient.DescribeStateMachineAsync(new DescribeStateMachineRequest { StateMachineArn = "arn:aws:states:us-east-1:000000000000:stateMachine:error-state-machine" }, cancellationToken);
50+
}
51+
}

test/contract-tests/images/applications/TestSimpleApp.AWSSDK.Core/TestSimpleApp.AWSSDK.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PackageReference Include="AWSSDK.SecretsManager" Version="4.0.0-preview" />
1414
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.0-preview" />
1515
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview" />
16+
<PackageReference Include="AWSSDK.StepFunctions" Version="4.0.0-preview" />
1617
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
1718
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
1819
<PackageReference Include="AWSSDK.Bedrock" Version="4.0.0-preview" />

test/contract-tests/tests/test/amazon/awssdk/awssdk_test.py

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
_AWS_KINESIS_STREAM_NAME: str = "aws.kinesis.stream_name"
3030
_AWS_SECRETSMANAGER_SECRET_ARN: str = "aws.secretsmanager.secret.arn"
3131
_AWS_SNS_TOPIC_ARN: str = "aws.sns.topic.arn"
32+
_AWS_STEPFUNCTIONS_ACTIVITY_ARN: str = "aws.stepfunctions.activity.arn"
33+
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: str = "aws.stepfunctions.state_machine.arn"
3234
_AWS_BEDROCK_GUARDRAIL_ID: str = "aws.bedrock.guardrail.id"
3335
_AWS_BEDROCK_AGENT_ID: str = "aws.bedrock.agent.id"
3436
_AWS_BEDROCK_KNOWLEDGE_BASE_ID: str = "aws.bedrock.knowledge_base.id"
@@ -83,10 +85,11 @@ def set_up_dependency_container(cls):
8385
)
8486
}
8587
cls._local_stack: LocalStackContainer = (
86-
LocalStackContainer(image="localstack/localstack:3.0.2")
88+
LocalStackContainer(image="localstack/localstack:4.0.0")
8789
.with_name("localstack")
88-
.with_services("s3", "secretsmanager", "sns", "sqs", "dynamodb", "kinesis")
90+
.with_services("s3", "secretsmanager", "sns", "sqs", "stepfunctions", "dynamodb", "kinesis")
8991
.with_env("DEFAULT_REGION", "us-west-2")
92+
# .with_env("PROVIDER_OVERRIDE_STEPFUNCTIONS", "legacy")
9093
.with_kwargs(network=NETWORK_NAME, networking_config=local_stack_networking_config)
9194
)
9295
cls._local_stack.start()
@@ -442,6 +445,101 @@ def test_sns_error(self):
442445
# span_name="SNS.CreateTopic"
443446
# )
444447

448+
def test_stepfunctions_create_state_machine(self):
449+
self.do_test_requests(
450+
"stepfunctions/createstatemachine/some-state-machine",
451+
"GET",
452+
200,
453+
0,
454+
0,
455+
rpc_service="SFN",
456+
remote_service="AWS::StepFunctions",
457+
remote_operation="CreateStateMachine",
458+
span_name="SFN.CreateStateMachine",
459+
)
460+
461+
def test_stepfunctions_describe_state_machine(self):
462+
self.do_test_requests(
463+
"stepfunctions/describestatemachine/some-state-machine",
464+
"GET",
465+
200,
466+
0,
467+
0,
468+
rpc_service="SFN",
469+
remote_service="AWS::StepFunctions",
470+
remote_operation="DescribeStateMachine",
471+
remote_resource_type="AWS::StepFunctions::StateMachine",
472+
remote_resource_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine",
473+
request_response_specific_attributes={
474+
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine",
475+
},
476+
span_name="SFN.DescribeStateMachine",
477+
)
478+
479+
def test_stepfunctions_create_activity(self):
480+
self.do_test_requests(
481+
"stepfunctions/createactivity/some-activity",
482+
"GET",
483+
200,
484+
0,
485+
0,
486+
rpc_service="SFN",
487+
remote_service="AWS::StepFunctions",
488+
remote_operation="CreateActivity",
489+
span_name="SFN.CreateActivity",
490+
)
491+
492+
def test_stepfunctions_describe_activity(self):
493+
self.do_test_requests(
494+
"stepfunctions/describeactivity/some-activity",
495+
"GET",
496+
200,
497+
0,
498+
0,
499+
rpc_service="SFN",
500+
remote_service="AWS::StepFunctions",
501+
remote_operation="DescribeActivity",
502+
remote_resource_type="AWS::StepFunctions::Activity",
503+
remote_resource_identifier="arn:aws:states:us-east-1:000000000000:activity:test-activity",
504+
request_response_specific_attributes={
505+
_AWS_STEPFUNCTIONS_ACTIVITY_ARN: "arn:aws:states:us-east-1:000000000000:activity:test-activity",
506+
},
507+
span_name="SFN.DescribeActivity",
508+
)
509+
510+
def test_stepfunctions_error(self):
511+
self.do_test_requests(
512+
"stepfunctions/error",
513+
"GET",
514+
400,
515+
1,
516+
0,
517+
rpc_service="SFN",
518+
remote_service="AWS::StepFunctions",
519+
remote_operation="DescribeStateMachine",
520+
remote_resource_type="AWS::StepFunctions::StateMachine",
521+
remote_resource_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:error-state-machine",
522+
request_response_specific_attributes={
523+
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:error-state-machine",
524+
},
525+
span_name="SFN.DescribeStateMachine",
526+
)
527+
528+
529+
# TODO: https://github.com/aws-observability/aws-otel-dotnet-instrumentation/issues/83
530+
# def test_stepfunctions_fault(self):
531+
# self.do_test_requests(
532+
# "stepfunctions/fault",
533+
# "GET",
534+
# 500,
535+
# 0,
536+
# 1,
537+
# rpc_service="SFN",
538+
# remote_service="AWS::StepFunctions",
539+
# remote_operation="CreateStateMachine",
540+
# span_name="SFN.CreateStateMachine",
541+
# )
542+
445543
def test_bedrock_get_guardrail(self):
446544
self.do_test_requests(
447545
"bedrock/getguardrail/get-guardrail",

0 commit comments

Comments
 (0)