Skip to content

Commit 710fe98

Browse files
committed
add contract tests for StepFunctions
1 parent 3867fa6 commit 710fe98

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
@@ -30,6 +30,8 @@
3030
_AWS_KINESIS_STREAM_NAME: str = "aws.kinesis.stream_name"
3131
_AWS_SECRETSMANAGER_SECRET_ARN: str = "aws.secretsmanager.secret.arn"
3232
_AWS_SNS_TOPIC_ARN: str = "aws.sns.topic.arn"
33+
_AWS_STEPFUNCTIONS_ACTIVITY_ARN: str = "aws.stepfunctions.activity.arn"
34+
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: str = "aws.stepfunctions.state_machine.arn"
3335
_AWS_BEDROCK_GUARDRAIL_ID: str = "aws.bedrock.guardrail.id"
3436
_AWS_BEDROCK_AGENT_ID: str = "aws.bedrock.agent.id"
3537
_AWS_BEDROCK_KNOWLEDGE_BASE_ID: str = "aws.bedrock.knowledge_base.id"
@@ -84,10 +86,11 @@ def set_up_dependency_container(cls):
8486
)
8587
}
8688
cls._local_stack: LocalStackContainer = (
87-
LocalStackContainer(image="localstack/localstack:3.0.2")
89+
LocalStackContainer(image="localstack/localstack:4.0.0")
8890
.with_name("localstack")
89-
.with_services("s3", "secretsmanager", "sns", "sqs", "dynamodb", "kinesis")
91+
.with_services("s3", "secretsmanager", "sns", "sqs", "stepfunctions", "dynamodb", "kinesis")
9092
.with_env("DEFAULT_REGION", "us-west-2")
93+
# .with_env("PROVIDER_OVERRIDE_STEPFUNCTIONS", "legacy")
9194
.with_kwargs(network=NETWORK_NAME, networking_config=local_stack_networking_config)
9295
)
9396
cls._local_stack.start()
@@ -455,6 +458,101 @@ def test_sns_error(self):
455458
# span_name="SNS.CreateTopic"
456459
# )
457460

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

0 commit comments

Comments
 (0)