Skip to content

Commit b33c0d8

Browse files
committed
add contract tests for SNS
1 parent 39d7948 commit b33c0d8

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Amazon.DynamoDBv2;
66
using Amazon.Kinesis;
77
using Amazon.S3;
8+
using Amazon.SimpleNotificationService;
89
using Amazon.SQS;
910
using TestSimpleApp.AWSSDK.Core;
1011

@@ -20,6 +21,7 @@
2021
.AddSingleton<IAmazonS3>(provider => new AmazonS3Client(new AmazonS3Config { ServiceURL = "http://localstack:4566", ForcePathStyle = true }))
2122
.AddSingleton<IAmazonSQS>(provider => new AmazonSQSClient(new AmazonSQSConfig { ServiceURL = "http://localstack:4566" }))
2223
.AddSingleton<IAmazonKinesis>(provider => new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
24+
.AddSingleton<IAmazonSimpleNotificationService>(provider => new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
2325
// Bedrock services are not supported by localstack, so we mock the API responses on the aws-application-signals-tests-testsimpleapp server.
2426
.AddSingleton<IAmazonBedrock>(provider => new AmazonBedrockClient(new AmazonBedrockConfig { ServiceURL = "http://localhost:8080" }))
2527
.AddSingleton<IAmazonBedrockRuntime>(provider => new AmazonBedrockRuntimeClient(new AmazonBedrockRuntimeConfig { ServiceURL = "http://localhost:8080" }))
@@ -30,15 +32,18 @@
3032
.AddKeyedSingleton<IAmazonS3>("fault-s3", new AmazonS3Client(AmazonClientConfigHelper.CreateConfig<AmazonS3Config>(true)))
3133
.AddKeyedSingleton<IAmazonSQS>("fault-sqs", new AmazonSQSClient(AmazonClientConfigHelper.CreateConfig<AmazonSQSConfig>(true)))
3234
.AddKeyedSingleton<IAmazonKinesis>("fault-kinesis", new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
35+
.AddKeyedSingleton<IAmazonSimpleNotificationService>("fault-sns", new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
3336
//error client
3437
.AddKeyedSingleton<IAmazonDynamoDB>("error-ddb", new AmazonDynamoDBClient(AmazonClientConfigHelper.CreateConfig<AmazonDynamoDBConfig>()))
3538
.AddKeyedSingleton<IAmazonS3>("error-s3", new AmazonS3Client(AmazonClientConfigHelper.CreateConfig<AmazonS3Config>()))
3639
.AddKeyedSingleton<IAmazonSQS>("error-sqs", new AmazonSQSClient(AmazonClientConfigHelper.CreateConfig<AmazonSQSConfig>()))
3740
.AddKeyedSingleton<IAmazonKinesis>("error-kinesis", new AmazonKinesisClient(new AmazonKinesisConfig { ServiceURL = "http://localstack:4566" }))
41+
.AddKeyedSingleton<IAmazonSimpleNotificationService>("error-sns", new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localstack:4566" }))
3842
.AddSingleton<S3Tests>()
3943
.AddSingleton<DynamoDBTests>()
4044
.AddSingleton<SQSTests>()
4145
.AddSingleton<KinesisTests>()
46+
.AddSingleton<SNSTests>()
4247
.AddSingleton<BedrockTests>();
4348

4449
var app = builder.Build();
@@ -121,6 +126,14 @@
121126
app.MapGet("kinesis/fault", (KinesisTests kinesis) => kinesis.Fault()).WithName("kinesis-fault").WithOpenApi();
122127
app.MapGet("kinesis/error", (KinesisTests kinesis) => kinesis.Error()).WithName("kinesis-error").WithOpenApi();
123128

129+
app.MapGet("sns/createtopic/some-topic", (SNSTests sns) => sns.CreateTopic())
130+
.WithName("create-topic")
131+
.WithOpenApi();
132+
133+
app.MapGet("sns/publish/some-topic", (SNSTests sns) => sns.Publish())
134+
.WithName("publish")
135+
.WithOpenApi();
136+
124137
app.MapGet("bedrock/getguardrail/get-guardrail", (BedrockTests bedrock) => bedrock.GetGuardrail())
125138
.WithName("get-guardrail")
126139
.WithOpenApi();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Amazon.SimpleNotificationService;
2+
using Amazon.SimpleNotificationService.Model;
3+
4+
namespace TestSimpleApp.AWSSDK.Core;
5+
6+
public class SNSTests(
7+
IAmazonSimpleNotificationService sns,
8+
[FromKeyedServices("fault-sns")] IAmazonSimpleNotificationService faultSns,
9+
[FromKeyedServices("error-sns")] IAmazonSimpleNotificationService errorSns,
10+
ILogger<SNSTests> logger) : ContractTest(logger)
11+
{
12+
public Task<CreateTopicResponse> CreateTopic()
13+
{
14+
return sns.CreateTopicAsync(new CreateTopicRequest { Name = "test-topic" });
15+
}
16+
17+
public Task<PublishResponse> Publish()
18+
{
19+
return sns.PublishAsync(new PublishRequest { TopicArn = "arn:aws:sns:us-east-1:000000000000:test-topic", Message = "test-message" });
20+
}
21+
22+
protected override Task CreateFault(CancellationToken cancellationToken)
23+
{
24+
return faultSns.CreateTopicAsync(new CreateTopicRequest { Name = "test-topic" }, cancellationToken);
25+
}
26+
27+
protected override Task CreateError(CancellationToken cancellationToken)
28+
{
29+
return errorSns.DeleteTopicAsync(new DeleteTopicRequest { TopicArn = "arn:aws:sns:us-east-1:000000000000:test-topic-error" });
30+
}
31+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0-preview" />
1111
<PackageReference Include="AWSSDK.Kinesis" Version="4.0.0-preview" />
1212
<PackageReference Include="AWSSDK.S3" Version="4.0.0-preview" />
13+
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.0-preview" />
1314
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview" />
1415
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
1516
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
16-
<PackageReference Include="AWSSDK.Bedrock" Version="4.0.0-preview"/>
17-
<PackageReference Include="AWSSDK.BedrockRuntime" Version="4.0.0-preview"/>
18-
<PackageReference Include="AWSSDK.BedrockAgent" Version="4.0.0-preview"/>
19-
<PackageReference Include="AWSSDK.BedrockAgentRuntime" Version="4.0.0-preview"/>
17+
<PackageReference Include="AWSSDK.Bedrock" Version="4.0.0-preview" />
18+
<PackageReference Include="AWSSDK.BedrockRuntime" Version="4.0.0-preview" />
19+
<PackageReference Include="AWSSDK.BedrockAgent" Version="4.0.0-preview" />
20+
<PackageReference Include="AWSSDK.BedrockAgentRuntime" Version="4.0.0-preview" />
2021
</ItemGroup>
2122

2223
</Project>

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_logger: Logger = getLogger(__name__)
2525
_logger.setLevel(INFO)
2626

27+
_AWS_SNS_TOPIC_ARN: str = "aws.sns.topic.arn"
2728
_AWS_SQS_QUEUE_URL: str = "aws.queue_url"
2829
_AWS_SQS_QUEUE_NAME: str = "aws.sqs.queue_name"
2930
_AWS_KINESIS_STREAM_NAME: str = "aws.kinesis.stream_name"
@@ -83,7 +84,7 @@ def set_up_dependency_container(cls):
8384
cls._local_stack: LocalStackContainer = (
8485
LocalStackContainer(image="localstack/localstack:3.0.2")
8586
.with_name("localstack")
86-
.with_services("s3", "sqs", "dynamodb", "kinesis")
87+
.with_services("s3", "sns", "sqs", "dynamodb", "kinesis")
8788
.with_env("DEFAULT_REGION", "us-west-2")
8889
.with_kwargs(network=NETWORK_NAME, networking_config=local_stack_networking_config)
8990
)
@@ -306,6 +307,36 @@ def test_kinesis_error(self):
306307
# span_name="Kinesis.CreateStream",
307308
# )
308309

310+
def test_sns_create_topic(self):
311+
self.do_test_requests(
312+
"sns/createtopic/some-topic",
313+
"GET",
314+
200,
315+
0,
316+
0,
317+
remote_service="AWS::SNS",
318+
remote_operation="CreateTopic",
319+
request_response_specific_attributes={},
320+
span_name="SNS.CreateTopic"
321+
)
322+
323+
def test_sns_publish(self):
324+
self.do_test_requests(
325+
"sns/publish/some-topic",
326+
"GET",
327+
200,
328+
0,
329+
0,
330+
remote_service="AWS::SNS",
331+
remote_operation="Publish",
332+
remote_resource_type="AWS::SNS::Topic",
333+
remote_resource_identifier="arn:aws:sns:us-east-1:000000000000:test-topic",
334+
request_response_specific_attributes={
335+
_AWS_SNS_TOPIC_ARN: "arn:aws:sns:us-east-1:000000000000:test-topic",
336+
},
337+
span_name="SNS.Publish",
338+
)
339+
309340
def test_bedrock_get_guardrail(self):
310341
self.do_test_requests(
311342
"bedrock/getguardrail/get-guardrail",

0 commit comments

Comments
 (0)