mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eventbridge): implement TagResource and UntagResource (#453)
This commit is contained in:
1 parent
e62f2a64d7
commit
ba62ae6b5d
3 files changed
+350
No files matched your search
+259
@@ -0,0 +1,259 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class EventBridgeTagResourceIntegrationTest {
|
||||
|
||||
private static final String EVENT_BRIDGE_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void tagResourceOnEventBus() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.CreateEventBus")
|
||||
.body("{\"Name\":\"tag-test-bus\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String busArn = given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeEventBus")
|
||||
.body("{\"Name\":\"tag-test-bus\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("Arn");
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.TagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "%s",
|
||||
"Tags": [
|
||||
{"Key": "env", "Value": "prod"},
|
||||
{"Key": "team", "Value": "infra"}
|
||||
]
|
||||
}
|
||||
""".formatted(busArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTagsForResource")
|
||||
.body("{\"ResourceARN\":\"" + busArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(2))
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("prod"))
|
||||
.body("Tags.find { it.Key == 'team' }.Value", equalTo("infra"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void tagResourceOnRule() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.PutRule")
|
||||
.body("{\"Name\":\"tag-test-rule\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String ruleArn = given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeRule")
|
||||
.body("{\"Name\":\"tag-test-rule\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("Arn");
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.TagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "%s",
|
||||
"Tags": [
|
||||
{"Key": "service", "Value": "payments"},
|
||||
{"Key": "priority", "Value": "high"}
|
||||
]
|
||||
}
|
||||
""".formatted(ruleArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTagsForResource")
|
||||
.body("{\"ResourceARN\":\"" + ruleArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(2))
|
||||
.body("Tags.find { it.Key == 'service' }.Value", equalTo("payments"))
|
||||
.body("Tags.find { it.Key == 'priority' }.Value", equalTo("high"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void untagResourceOnEventBus() {
|
||||
String busArn = given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeEventBus")
|
||||
.body("{\"Name\":\"tag-test-bus\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("Arn");
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.UntagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "%s",
|
||||
"TagKeys": ["env"]
|
||||
}
|
||||
""".formatted(busArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTagsForResource")
|
||||
.body("{\"ResourceARN\":\"" + busArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(1))
|
||||
.body("Tags.find { it.Key == 'team' }.Value", equalTo("infra"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void untagResourceOnRule() {
|
||||
String ruleArn = given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeRule")
|
||||
.body("{\"Name\":\"tag-test-rule\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("Arn");
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.UntagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "%s",
|
||||
"TagKeys": ["service", "priority"]
|
||||
}
|
||||
""".formatted(ruleArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTagsForResource")
|
||||
.body("{\"ResourceARN\":\"" + ruleArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void tagResourceNotFound() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.TagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "arn:aws:events:us-east-1:000000000000:event-bus/nonexistent",
|
||||
"Tags": [{"Key": "k", "Value": "v"}]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void untagResourceNotFound() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.UntagResource")
|
||||
.body("""
|
||||
{
|
||||
"ResourceARN": "arn:aws:events:us-east-1:000000000000:rule/nonexistent-rule",
|
||||
"TagKeys": ["k"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void cleanup() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DeleteRule")
|
||||
.body("{\"Name\":\"tag-test-rule\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DeleteEventBus")
|
||||
.body("{\"Name\":\"tag-test-bus\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user