mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): create inline SNS subscriptions (#6443)
This commit is contained in:
1 parent
fac6378abd
commit
7d4caf2291
5 files changed
+532
-26
No files matched your search
+199
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.testing.MutableClock;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -6689,6 +6690,204 @@ class CloudFormationIntegrationTest {
|
||||
.body("authorizerId", equalTo(secondAuth));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_snsTopicWithInlineSubscriptions() {
|
||||
String topicArn = "arn:aws:sns:us-east-1:000000000000:cfn-inline-subs-topic";
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyQueue": {
|
||||
"Type": "AWS::SQS::Queue",
|
||||
"Properties": {"QueueName": "cfn-inline-subs-queue"}
|
||||
},
|
||||
"MyTopic": {
|
||||
"Type": "AWS::SNS::Topic",
|
||||
"Properties": {
|
||||
"TopicName": "cfn-inline-subs-topic",
|
||||
"Subscription": [
|
||||
{"Protocol": "sqs", "Endpoint": {"Fn::GetAtt": ["MyQueue", "Arn"]}},
|
||||
{"Protocol": "email", "Endpoint": "alerts@example.com"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-inline-subs-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String subscriptions = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListSubscriptionsByTopic")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("arn:aws:sqs:us-east-1:000000000000:cfn-inline-subs-queue"))
|
||||
.body(containsString("alerts@example.com"))
|
||||
.extract().asString();
|
||||
String sqsArn = new XmlPath(subscriptions)
|
||||
.getString("**.find { it.Protocol == 'sqs' }.SubscriptionArn");
|
||||
String emailArn = new XmlPath(subscriptions)
|
||||
.getString("**.find { it.Protocol == 'email' }.SubscriptionArn");
|
||||
assertTrue(sqsArn.startsWith(topicArn + ":"), sqsArn);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "GetSubscriptionAttributes")
|
||||
.formParam("SubscriptionArn", emailArn)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("**.find { it.key == 'PendingConfirmation' }.value", equalTo("true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_snsTopicResolvesConditionalInlineSubscriptions() {
|
||||
String topicArn = "arn:aws:sns:us-east-1:000000000000:cfn-conditional-subs-topic";
|
||||
String template = """
|
||||
{
|
||||
"Conditions": {"Include": {"Fn::Equals": ["yes", "yes"]}},
|
||||
"Resources": {
|
||||
"MyTopic": {
|
||||
"Type": "AWS::SNS::Topic",
|
||||
"Properties": {
|
||||
"TopicName": "cfn-conditional-subs-topic",
|
||||
"Subscription": {"Fn::If": ["Include", [
|
||||
{"Protocol": "email", "Endpoint": "selected@example.com"},
|
||||
{"Fn::If": ["Include", {"Ref": "AWS::NoValue"},
|
||||
{"Protocol": "email", "Endpoint": "omitted@example.com"}]}
|
||||
], {"Ref": "AWS::NoValue"}]}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-conditional-subs-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListSubscriptionsByTopic")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("selected@example.com"))
|
||||
.body(not(containsString("omitted@example.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateStack_snsTopicRemovesOnlyDroppedInlineSubscriptions() {
|
||||
String topicArn = "arn:aws:sns:us-east-1:000000000000:cfn-update-inline-subs-topic";
|
||||
String initialTemplate = """
|
||||
{"Resources":{"MyTopic":{"Type":"AWS::SNS::Topic","Properties":{
|
||||
"TopicName":"cfn-update-inline-subs-topic",
|
||||
"Subscription":[{"Protocol":"email","Endpoint":"inline@example.com"}]}}}}
|
||||
""";
|
||||
String updatedTemplate = """
|
||||
{"Resources":{"MyTopic":{"Type":"AWS::SNS::Topic","Properties":{
|
||||
"TopicName":"cfn-update-inline-subs-topic"}}}}
|
||||
""";
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-update-inline-subs-stack")
|
||||
.formParam("TemplateBody", initialTemplate)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Subscribe")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("Protocol", "email")
|
||||
.formParam("Endpoint", "manual@example.com")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", "cfn-update-inline-subs-stack")
|
||||
.formParam("TemplateBody", updatedTemplate)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListSubscriptionsByTopic")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("manual@example.com"))
|
||||
.body(not(containsString("inline@example.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_snsTopicSubscribesSameStackLambda() {
|
||||
String functionName = "cfn-inline-subs-lambda";
|
||||
String functionArn = "arn:aws:lambda:us-east-1:000000000000:function:" + functionName;
|
||||
String topicArn = "arn:aws:sns:us-east-1:000000000000:cfn-lambda-inline-subs-topic";
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"Fn": {"Type":"AWS::Lambda::Function","Properties":{
|
||||
"FunctionName":"%s","Runtime":"python3.12","Handler":"index.handler",
|
||||
"Role":"arn:aws:iam::000000000000:role/cfn-test-lambda-role",
|
||||
"Code":{"ZipFile":"def handler(e, c): return 'ok'"}}},
|
||||
"Topic": {"Type":"AWS::SNS::Topic","Properties":{
|
||||
"TopicName":"cfn-lambda-inline-subs-topic",
|
||||
"Subscription":[{"Protocol":"lambda","Endpoint":{"Fn::GetAtt":["Fn","Arn"]}}]}},
|
||||
"Perm": {"Type":"AWS::Lambda::Permission","Properties":{
|
||||
"FunctionName":{"Ref":"Fn"},"Action":"lambda:InvokeFunction",
|
||||
"Principal":"sns.amazonaws.com","SourceArn":{"Ref":"Topic"}}}
|
||||
}
|
||||
}
|
||||
""".formatted(functionName);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-lambda-inline-subs-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "cfn-lambda-inline-subs-stack")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
String lambdaSubscriptionArn = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListSubscriptionsByTopic")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString(functionArn))
|
||||
.extract().xmlPath().getString("**.find { it.Protocol == 'lambda' }.SubscriptionArn");
|
||||
assertTrue(lambdaSubscriptionArn.startsWith(topicArn + ":"), lambdaSubscriptionArn);
|
||||
given()
|
||||
.when().get("/2015-03-31/functions/" + functionName + "/policy")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("sns.amazonaws.com"))
|
||||
.body(containsString(topicArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_snsSqsFifoWithContentBasedDeduplicationAndSubscription() {
|
||||
String stackName = "cfn-sns-sqs-fifo-stack";
|
||||
|
||||
+200
@@ -68,6 +68,17 @@ class SnsCfnProvisionerTest {
|
||||
}
|
||||
return values;
|
||||
});
|
||||
when(engine.resolveNodeOmittingNoValue(any())).thenAnswer(i -> i.getArgument(0));
|
||||
when(sns.listTopics(REGION)).thenReturn(List.of());
|
||||
when(sns.createTopicWithStatus(anyString(), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenAnswer(i -> new SnsService.TopicCreation(
|
||||
sns.createTopic(i.getArgument(0), i.getArgument(1), i.getArgument(2), i.getArgument(3)),
|
||||
false));
|
||||
when(sns.listSubscriptionsByTopic(TOPIC_ARN, REGION)).thenReturn(List.of());
|
||||
when(sns.subscribeWithStatus(anyString(), anyString(), anyString(), eq(REGION), anyMap()))
|
||||
.thenAnswer(i -> new SnsService.SubscriptionCreation(
|
||||
sns.subscribe(i.getArgument(0), i.getArgument(1), i.getArgument(2), i.getArgument(3),
|
||||
i.getArgument(4)), true));
|
||||
ctx = new ProvisionContext(engine, REGION, "000000000000", "my-stack");
|
||||
}
|
||||
|
||||
@@ -116,6 +127,195 @@ class SnsCfnProvisionerTest {
|
||||
r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicCreatesInlineSubscriptions() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION))).thenReturn(topic(TOPIC_ARN));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("lambda"), eq("arn:lambda"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:sub"));
|
||||
|
||||
provision("AWS::SNS::Topic", """
|
||||
{"TopicName": "events", "Subscription": [
|
||||
{"Protocol": "lambda", "Endpoint": "arn:lambda"}
|
||||
]}
|
||||
""");
|
||||
|
||||
verify(sns).subscribe(TOPIC_ARN, "lambda", "arn:lambda", REGION, Map.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicWithoutPropertiesStillCreates() {
|
||||
when(sns.createTopic(anyString(), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("Topic");
|
||||
r.setResourceType("AWS::SNS::Topic");
|
||||
r.setAttributes(new HashMap<>());
|
||||
|
||||
provisioner.provision(r, null, ctx);
|
||||
|
||||
assertEquals(TOPIC_ARN, r.getPhysicalId());
|
||||
verify(sns, never()).subscribe(anyString(), anyString(), anyString(), anyString(), anyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicUpdateRemovesOnlyItsDroppedInlineSubscription() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
Subscription old = subscription("arn:old");
|
||||
old.setProtocol("sqs");
|
||||
old.setEndpoint("arn:old-queue");
|
||||
Subscription manual = subscription("arn:manual");
|
||||
manual.setProtocol("sqs");
|
||||
manual.setEndpoint("arn:manual-queue");
|
||||
when(sns.listSubscriptionsByTopic(TOPIC_ARN, REGION))
|
||||
.thenReturn(List.of(), List.of(old, manual));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:old-queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(old);
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:new-queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:new"));
|
||||
|
||||
StackResource r = provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[{"Protocol":"sqs","Endpoint":"arn:old-queue"}]}
|
||||
""");
|
||||
provisioner.provision(r, props("""
|
||||
{"TopicName":"events","Subscription":[{"Protocol":"sqs","Endpoint":"arn:new-queue"}]}
|
||||
"""), new ProvisionContext(engine, REGION, "000000000000", "my-stack", TOPIC_ARN));
|
||||
|
||||
verify(sns).unsubscribe("arn:old", REGION);
|
||||
verify(sns, never()).unsubscribe("arn:manual", REGION);
|
||||
verify(sns).subscribe(TOPIC_ARN, "sqs", "arn:new-queue", REGION, Map.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicUpdateRemovesInlineSubscriptionWhenPropertyIsDropped() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
Subscription old = subscription("arn:old");
|
||||
old.setProtocol("sqs");
|
||||
old.setEndpoint("arn:old-queue");
|
||||
when(sns.listSubscriptionsByTopic(TOPIC_ARN, REGION))
|
||||
.thenReturn(List.of(), List.of(old));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:old-queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(old);
|
||||
|
||||
StackResource r = provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[{"Protocol":"sqs","Endpoint":"arn:old-queue"}]}
|
||||
""");
|
||||
provisioner.provision(r, props("""
|
||||
{"TopicName":"events"}
|
||||
"""),
|
||||
new ProvisionContext(engine, REGION, "000000000000", "my-stack", TOPIC_ARN));
|
||||
|
||||
verify(sns).unsubscribe("arn:old", REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedInlineSubscriptionRemovesNewTopic() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
when(sns.createTopicWithStatus(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(new SnsService.TopicCreation(topic(TOPIC_ARN), true));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:first"));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
|
||||
assertThrows(AwsException.class, () -> provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[
|
||||
{"Protocol":"sqs","Endpoint":"arn:queue"},
|
||||
{"Protocol":"https","Endpoint":"http://wrong"}]}
|
||||
"""));
|
||||
|
||||
verify(sns).deleteTopic(TOPIC_ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedInlineSubscriptionKeepsPreexistingTopic() {
|
||||
Topic preexisting = topic(TOPIC_ARN);
|
||||
preexisting.setName("events");
|
||||
when(sns.listTopics(REGION)).thenReturn(List.of(preexisting));
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(preexisting);
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:first"));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
|
||||
assertThrows(AwsException.class, () -> provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[
|
||||
{"Protocol":"sqs","Endpoint":"arn:queue"},
|
||||
{"Protocol":"https","Endpoint":"http://wrong"}]}
|
||||
"""));
|
||||
|
||||
verify(sns).unsubscribe("arn:first", REGION);
|
||||
verify(sns, never()).deleteTopic(TOPIC_ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicCreationStatusAvoidsListThenCreateRace() {
|
||||
Topic createdByAnotherCaller = topic(TOPIC_ARN);
|
||||
createdByAnotherCaller.setName("events");
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(createdByAnotherCaller);
|
||||
when(sns.createTopicWithStatus(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(new SnsService.TopicCreation(createdByAnotherCaller, false));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
when(sns.subscribeWithStatus(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
|
||||
assertThrows(AwsException.class, () -> provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[
|
||||
{"Protocol":"https","Endpoint":"http://wrong"}]}
|
||||
"""));
|
||||
|
||||
verify(sns, never()).deleteTopic(TOPIC_ARN, REGION);
|
||||
verify(sns, never()).listTopics(REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inlineSubscriptionCreationStatusProtectsAnotherCaller() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
when(sns.createTopicWithStatus(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(new SnsService.TopicCreation(topic(TOPIC_ARN), false));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:other"));
|
||||
when(sns.subscribeWithStatus(eq(TOPIC_ARN), eq("sqs"), eq("arn:queue"), eq(REGION), anyMap()))
|
||||
.thenReturn(new SnsService.SubscriptionCreation(subscription("arn:other"), false));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
when(sns.subscribeWithStatus(eq(TOPIC_ARN), eq("https"), eq("http://wrong"), eq(REGION), anyMap()))
|
||||
.thenThrow(new AwsException("InvalidParameter", "Endpoint scheme mismatch", 400));
|
||||
|
||||
assertThrows(AwsException.class, () -> provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":[
|
||||
{"Protocol":"sqs","Endpoint":"arn:queue"},
|
||||
{"Protocol":"https","Endpoint":"http://wrong"}]}
|
||||
"""));
|
||||
|
||||
verify(sns, never()).unsubscribe("arn:other", REGION);
|
||||
verify(sns, never()).deleteTopic(TOPIC_ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicResolvesConditionalSubscriptionList() {
|
||||
when(sns.createTopic(eq("events"), anyMap(), anyMap(), eq(REGION)))
|
||||
.thenReturn(topic(TOPIC_ARN));
|
||||
when(sns.subscribe(eq(TOPIC_ARN), eq("sqs"), eq("arn:selected"), eq(REGION), anyMap()))
|
||||
.thenReturn(subscription("arn:selected-sub"));
|
||||
when(engine.resolveNodeOmittingNoValue(any())).thenReturn(props("""
|
||||
[{"Protocol":"sqs","Endpoint":"arn:selected"}]
|
||||
"""));
|
||||
|
||||
provision("AWS::SNS::Topic", """
|
||||
{"TopicName":"events","Subscription":{"Fn::If":["Include",
|
||||
[{"Protocol":"sqs","Endpoint":"arn:selected"}],{"Ref":"AWS::NoValue"}]}}
|
||||
""");
|
||||
|
||||
verify(sns).subscribe(TOPIC_ARN, "sqs", "arn:selected", REGION, Map.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnnamedTopicGetsAGeneratedStackScopedName() {
|
||||
ArgumentCaptor<String> name = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
@@ -69,6 +69,18 @@ class SnsServiceTest {
|
||||
assertEquals("arn:aws:sns:us-east-1:000000000000:my-topic", topic.getTopicArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTopicWithStatusReportsWhetherTheTopicWasCreated() {
|
||||
SnsService.TopicCreation first = snsService.createTopicWithStatus(
|
||||
"status-topic", null, null, REGION);
|
||||
SnsService.TopicCreation second = snsService.createTopicWithStatus(
|
||||
"status-topic", null, null, REGION);
|
||||
|
||||
assertTrue(first.created());
|
||||
assertFalse(second.created());
|
||||
assertSame(first.topic(), second.topic());
|
||||
}
|
||||
|
||||
@Test
|
||||
void smsAttributesAreScopedToAccountAndRegion() {
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
@@ -250,6 +262,19 @@ class SnsServiceTest {
|
||||
assertEquals(Map.of("attr1", "value1", "attr2", "value2"), sub.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribeWithStatusReportsWhetherTheSubscriptionWasCreated() {
|
||||
Topic topic = snsService.createTopic("status-topic", null, null, REGION);
|
||||
SnsService.SubscriptionCreation first = snsService.subscribeWithStatus(
|
||||
topic.getTopicArn(), "sqs", "http://localhost:4566/queue", REGION, Map.of());
|
||||
SnsService.SubscriptionCreation second = snsService.subscribeWithStatus(
|
||||
topic.getTopicArn(), "sqs", "http://localhost:4566/queue", REGION, Map.of());
|
||||
|
||||
assertTrue(first.created());
|
||||
assertFalse(second.created());
|
||||
assertSame(first.subscription(), second.subscription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribe_firehoseRequiresValidRoleArn() {
|
||||
Topic topic = snsService.createTopic("firehose-topic", null, null, REGION);
|
||||
|
||||
Reference in new issue
Block a user