Skip to content

Commit 38d965c

Browse files
committed
update tests to create some resources ahead of time
1 parent 330df33 commit 38d965c

File tree

4 files changed

+39
-69
lines changed

4 files changed

+39
-69
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,17 @@
147147
app.MapGet("secretsmanager/fault", (SecretsManagerTests secretsManager) => secretsManager.Fault()).WithName("secretsmanager-fault").WithOpenApi();
148148
app.MapGet("secretsmanager/error", (SecretsManagerTests secretsManager) => secretsManager.Error()).WithName("secretsmanager-error").WithOpenApi();
149149

150-
app.MapGet("sns/createtopic/some-topic", (SNSTests sns) => sns.CreateTopic())
151-
.WithName("create-topic")
152-
.WithOpenApi();
153-
154150
app.MapGet("sns/publish/some-topic", (SNSTests sns) => sns.Publish())
155151
.WithName("publish")
156152
.WithOpenApi();
157153

158154
app.MapGet("sns/fault", (SNSTests sns) => sns.Fault()).WithName("sns-fault").WithOpenApi();
159155
app.MapGet("sns/error", (SNSTests sns) => sns.Error()).WithName("sns-error").WithOpenApi();
160156

161-
app.MapGet("stepfunctions/createstatemachine/some-state-machine", (StepFunctionsTests stepFunctions) => stepFunctions.CreateStateMachine())
162-
.WithName("create-state-machine")
163-
.WithOpenApi();
164-
165157
app.MapGet("stepfunctions/describestatemachine/some-state-machine", (StepFunctionsTests stepFunctions) => stepFunctions.DescribeStateMachine())
166158
.WithName("describe-state-machine")
167159
.WithOpenApi();
168160

169-
app.MapGet("stepfunctions/createactivity/some-activity", (StepFunctionsTests stepFunctions) => stepFunctions.CreateActivity())
170-
.WithName("create-activity")
171-
.WithOpenApi();
172-
173161
app.MapGet("stepfunctions/describeactivity/some-activity", (StepFunctionsTests stepFunctions) => stepFunctions.DescribeActivity())
174162
.WithName("describe-activity")
175163
.WithOpenApi();
@@ -225,6 +213,20 @@
225213
.WithName("retrieve")
226214
.WithOpenApi();
227215

216+
// Create some resources in advance to be accessed by tests
217+
async Task PrepareAWSServer(IServiceProvider services)
218+
{
219+
var snsTests = services.GetRequiredService<SNSTests>();
220+
var stepfunctionsTests = services.GetRequiredService<StepFunctionsTests>();
221+
222+
// Create a topic for the SNS tests
223+
await snsTests.CreateTopic("test-topic");
224+
225+
// Create a state machine and activity for the Step Functions tests
226+
await stepfunctionsTests.CreateStateMachine("test-state-machine");
227+
await stepfunctionsTests.CreateActivity("test-activity");
228+
}
229+
228230
// Reroute the Bedrock API calls to our mock responses in BedrockTests. While other services use localstack to handle the requests,
229231
// we write our own responses with the necessary data to mimic the expected behavior of the Bedrock services.
230232
app.MapGet("guardrails/test-guardrail", (BedrockTests bedrock) => bedrock.GetGuardrailResponse());
@@ -241,4 +243,6 @@
241243
app.MapPost("agents/test-agent/agentAliases/test-agent-alias/sessions/test-session/text", (BedrockTests bedrock) => bedrock.InvokeAgentResponse());
242244
app.MapPost("knowledgebases/test-knowledge-base/retrieve", (BedrockTests bedrock) => bedrock.RetrieveResponse());
243245

246+
await PrepareAWSServer(app.Services);
247+
244248
app.Run();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class SNSTests(
99
[FromKeyedServices("error-sns")] IAmazonSimpleNotificationService errorSns,
1010
ILogger<SNSTests> logger) : ContractTest(logger)
1111
{
12-
public Task<CreateTopicResponse> CreateTopic()
12+
public Task<CreateTopicResponse> CreateTopic(string name)
1313
{
14-
return sns.CreateTopicAsync(new CreateTopicRequest { Name = "test-topic" });
14+
return sns.CreateTopicAsync(new CreateTopicRequest { Name = name });
1515
}
1616

1717
public Task<PublishResponse> Publish()
@@ -21,7 +21,7 @@ public Task<PublishResponse> Publish()
2121

2222
protected override Task CreateFault(CancellationToken cancellationToken)
2323
{
24-
return faultSns.CreateTopicAsync(new CreateTopicRequest { Name = "test-topic" }, cancellationToken);
24+
return faultSns.GetTopicAttributesAsync(new GetTopicAttributesRequest { TopicArn = "arn:aws:sns:us-east-1:000000000000:invalid-topic" }, cancellationToken);
2525
}
2626

2727
protected override Task CreateError(CancellationToken cancellationToken)

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ public class StepFunctionsTests(
99
[FromKeyedServices("error-stepfunctions")] IAmazonStepFunctions errorClient,
1010
ILogger<StepFunctionsTests> logger) : ContractTest(logger)
1111
{
12-
public Task<CreateStateMachineResponse> CreateStateMachine()
12+
public Task<CreateStateMachineResponse> CreateStateMachine(string name)
1313
{
1414
return stepFunctions.CreateStateMachineAsync(new CreateStateMachineRequest
1515
{
16-
Name = "test-state-machine",
16+
Name = name,
1717
Definition = "{\"StartAt\":\"TestState\",\"States\":{\"TestState\":{\"Type\":\"Pass\",\"End\":true,\"Result\":\"Result\"}}}",
1818
RoleArn = "arn:aws:iam::000000000000:role/stepfunctions-role"
1919
});
2020
}
2121

22-
public Task<DescribeStateMachineResponse> DescribeStateMachine()
22+
public Task<CreateActivityResponse> CreateActivity(string name)
2323
{
24-
return stepFunctions.DescribeStateMachineAsync(new DescribeStateMachineRequest { StateMachineArn = "arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine" });
24+
return stepFunctions.CreateActivityAsync(new CreateActivityRequest { Name = name });
2525
}
2626

27-
public Task<CreateActivityResponse> CreateActivity()
27+
public Task<DescribeStateMachineResponse> DescribeStateMachine()
2828
{
29-
return stepFunctions.CreateActivityAsync(new CreateActivityRequest { Name = "test-activity" });
29+
return stepFunctions.DescribeStateMachineAsync(new DescribeStateMachineRequest { StateMachineArn = "arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine" });
3030
}
3131

3232
public Task<DescribeActivityResponse> DescribeActivity()
@@ -36,11 +36,9 @@ public Task<DescribeActivityResponse> DescribeActivity()
3636

3737
protected override Task CreateFault(CancellationToken cancellationToken)
3838
{
39-
return faultClient.CreateStateMachineAsync(new CreateStateMachineRequest
39+
return faultClient.ListStateMachineVersionsAsync(new ListStateMachineVersionsRequest
4040
{
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"
41+
StateMachineArn = "arn:aws:states:us-east-1:000000000000:stateMachine:invalid-state-machine"
4442
}, cancellationToken);
4543
}
4644

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

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,6 @@ def test_secretsmanager_error(self):
384384
# span_name="Secrets Manager.CreateSecret",
385385
# )
386386

387-
def test_sns_create_topic(self):
388-
self.do_test_requests(
389-
"sns/createtopic/some-topic",
390-
"GET",
391-
200,
392-
0,
393-
0,
394-
remote_service="AWS::SNS",
395-
remote_operation="CreateTopic",
396-
request_response_specific_attributes={},
397-
span_name="SNS.CreateTopic"
398-
)
399-
400387
def test_sns_publish(self):
401388
self.do_test_requests(
402389
"sns/publish/some-topic",
@@ -440,23 +427,13 @@ def test_sns_error(self):
440427
# 0,
441428
# 1,
442429
# remote_service="AWS::SNS",
443-
# remote_operation="CreateTopic",
444-
# request_response_specific_attributes={},
445-
# span_name="SNS.CreateTopic"
430+
# remote_operation="GetTopicAttributes",
431+
# remote_resource_type="AWS::SNS::Topic",
432+
# remote_resource_identifier="arn:aws:sns:us-east-1:000000000000:invalid-topic",
433+
# request_response_specific_attributes={
434+
# _AWS_SNS_TOPIC_ARN: "arn:aws:sns:us-east-1:000000000000:invalid-topic",},
435+
# span_name="SNS.GetTopicAttributes"
446436
# )
447-
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-
)
460437

461438
def test_stepfunctions_describe_state_machine(self):
462439
self.do_test_requests(
@@ -476,19 +453,6 @@ def test_stepfunctions_describe_state_machine(self):
476453
span_name="SFN.DescribeStateMachine",
477454
)
478455

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-
492456
def test_stepfunctions_describe_activity(self):
493457
self.do_test_requests(
494458
"stepfunctions/describeactivity/some-activity",
@@ -536,8 +500,12 @@ def test_stepfunctions_error(self):
536500
# 1,
537501
# rpc_service="SFN",
538502
# remote_service="AWS::StepFunctions",
539-
# remote_operation="CreateStateMachine",
540-
# span_name="SFN.CreateStateMachine",
503+
# remote_operation="ListStateMachineVersions",
504+
# remote_resource_type="AWS::StepFunctions::StateMachine",
505+
# remote_resource_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:invalid-state-machine",
506+
# request_response_specific_attributes={
507+
# _AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:invalid-state-machine",},
508+
# span_name="SFN.ListStateMachineVersions",
541509
# )
542510

543511
def test_bedrock_get_guardrail(self):

0 commit comments

Comments
 (0)