feat(pipes): add EventBridge Pipes service skeleton with CRUD API (#539)

This commit is contained in:
Christine Nguyen authored and GitHub committed 2026-04-21 07:23:49 -05:00
1 parent 59c1d727fc
commit 9f231afc3b
11 files changed
+1124 -2

No files matched your search

@@ -50,7 +50,8 @@ class HealthControllerIntegrationTest {
"ecr": "running",
"tagging": "running",
"bedrock-runtime": "running",
"eks": "running"
"eks": "running",
"pipes": "running"
},
"edition": "floci-always-free",
"version": "dev"
@@ -0,0 +1,215 @@
package io.github.hectorvent.floci.services.pipes;
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 PipesIntegrationTest {
@Test
@Order(1)
void createPipe() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:sqs:us-east-1:000000000000:source-queue",
"Target": "arn:aws:sqs:us-east-1:000000000000:target-queue",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role",
"Description": "Integration test pipe",
"DesiredState": "RUNNING"
}
""")
.when()
.post("/v1/pipes/integration-pipe")
.then()
.statusCode(200)
.body("Name", equalTo("integration-pipe"))
.body("Arn", containsString("pipe/integration-pipe"))
.body("Source", equalTo("arn:aws:sqs:us-east-1:000000000000:source-queue"))
.body("Target", equalTo("arn:aws:sqs:us-east-1:000000000000:target-queue"))
.body("CurrentState", equalTo("RUNNING"))
.body("DesiredState", equalTo("RUNNING"));
}
@Test
@Order(2)
void createDuplicatePipeReturnsConflict() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:sqs:us-east-1:000000000000:source-queue",
"Target": "arn:aws:sqs:us-east-1:000000000000:target-queue",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role"
}
""")
.when()
.post("/v1/pipes/integration-pipe")
.then()
.statusCode(409);
}
@Test
@Order(3)
void describePipe() {
given()
.contentType("application/json")
.when()
.get("/v1/pipes/integration-pipe")
.then()
.statusCode(200)
.body("Name", equalTo("integration-pipe"))
.body("Source", equalTo("arn:aws:sqs:us-east-1:000000000000:source-queue"))
.body("Description", equalTo("Integration test pipe"));
}
@Test
@Order(4)
void describeNonexistentPipeReturns404() {
given()
.contentType("application/json")
.when()
.get("/v1/pipes/does-not-exist")
.then()
.statusCode(404);
}
@Test
@Order(5)
void listPipes() {
given()
.contentType("application/json")
.body("""
{
"Source": "arn:aws:sqs:us-east-1:000000000000:other-source",
"Target": "arn:aws:sqs:us-east-1:000000000000:other-target",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role",
"DesiredState": "STOPPED"
}
""")
.when()
.post("/v1/pipes/second-pipe")
.then()
.statusCode(200);
given()
.contentType("application/json")
.when()
.get("/v1/pipes")
.then()
.statusCode(200)
.body("Pipes.size()", equalTo(2));
}
@Test
@Order(6)
void listPipesWithNamePrefixFilter() {
given()
.contentType("application/json")
.queryParam("NamePrefix", "integration")
.when()
.get("/v1/pipes")
.then()
.statusCode(200)
.body("Pipes.size()", equalTo(1))
.body("Pipes[0].Name", equalTo("integration-pipe"));
}
@Test
@Order(7)
void updatePipe() {
given()
.contentType("application/json")
.body("""
{
"Target": "arn:aws:sqs:us-east-1:000000000000:updated-target",
"Description": "Updated description",
"DesiredState": "STOPPED"
}
""")
.when()
.put("/v1/pipes/integration-pipe")
.then()
.statusCode(200)
.body("Target", equalTo("arn:aws:sqs:us-east-1:000000000000:updated-target"))
.body("CurrentState", equalTo("STOPPED"))
.body("DesiredState", equalTo("STOPPED"));
}
@Test
@Order(8)
void startPipe() {
given()
.contentType("application/json")
.when()
.post("/v1/pipes/integration-pipe/start")
.then()
.statusCode(200)
.body("CurrentState", equalTo("RUNNING"))
.body("DesiredState", equalTo("RUNNING"));
}
@Test
@Order(9)
void stopPipe() {
given()
.contentType("application/json")
.when()
.post("/v1/pipes/integration-pipe/stop")
.then()
.statusCode(200)
.body("CurrentState", equalTo("STOPPED"))
.body("DesiredState", equalTo("STOPPED"));
}
@Test
@Order(10)
void deletePipe() {
given()
.contentType("application/json")
.when()
.delete("/v1/pipes/integration-pipe")
.then()
.statusCode(200);
given()
.contentType("application/json")
.when()
.get("/v1/pipes/integration-pipe")
.then()
.statusCode(404);
}
@Test
@Order(11)
void deleteNonexistentPipeReturns404() {
given()
.contentType("application/json")
.when()
.delete("/v1/pipes/ghost-pipe")
.then()
.statusCode(404);
}
@Test
@Order(12)
void createPipeMissingSourceReturns400() {
given()
.contentType("application/json")
.body("""
{
"Target": "arn:aws:sqs:us-east-1:000000000000:target-queue",
"RoleArn": "arn:aws:iam::000000000000:role/pipe-role"
}
""")
.when()
.post("/v1/pipes/bad-pipe")
.then()
.statusCode(400);
}
}
@@ -0,0 +1,273 @@
package io.github.hectorvent.floci.services.pipes;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.pipes.model.DesiredState;
import io.github.hectorvent.floci.services.pipes.model.Pipe;
import io.github.hectorvent.floci.services.pipes.model.PipeState;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
class PipesServiceTest {
private PipesService pipesService;
@BeforeEach
void setUp() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
when(config.defaultAccountId()).thenReturn("000000000000");
pipesService = new PipesService(storageFactory, config);
}
@Test
void createPipe() {
Pipe pipe = pipesService.createPipe("test-pipe",
"arn:aws:sqs:us-east-1:000000000000:source-queue",
"arn:aws:sqs:us-east-1:000000000000:target-queue",
"arn:aws:iam::000000000000:role/pipe-role",
"A test pipe", DesiredState.RUNNING, null,
null, null, null, Map.of("env", "test"), "us-east-1");
assertNotNull(pipe);
assertEquals("test-pipe", pipe.getName());
assertEquals("arn:aws:pipes:us-east-1:000000000000:pipe/test-pipe", pipe.getArn());
assertEquals(DesiredState.RUNNING, pipe.getDesiredState());
assertEquals(PipeState.RUNNING, pipe.getCurrentState());
assertEquals("A test pipe", pipe.getDescription());
assertNotNull(pipe.getCreationTime());
assertNotNull(pipe.getLastModifiedTime());
assertEquals("test", pipe.getTags().get("env"));
}
@Test
void createPipeDefaultsDesiredStateToRunning() {
Pipe pipe = pipesService.createPipe("pipe-no-state",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
assertEquals(DesiredState.RUNNING, pipe.getDesiredState());
assertEquals(PipeState.RUNNING, pipe.getCurrentState());
}
@Test
void createPipeDuplicateNameThrowsConflict() {
pipesService.createPipe("dup-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("dup-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1"));
assertEquals("ConflictException", ex.getErrorCode());
assertEquals(409, ex.getHttpStatus());
}
@Test
void createPipeMissingRequiredFieldsThrowsValidation() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.createPipe(null, "source", "target", "role",
null, null, null, null, null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("name", null, "target", "role",
null, null, null, null, null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("name", "source", null, "role",
null, null, null, null, null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
ex = assertThrows(AwsException.class, () ->
pipesService.createPipe("name", "source", "target", null,
null, null, null, null, null, null, null, "us-east-1"));
assertEquals("ValidationException", ex.getErrorCode());
}
@Test
void describePipe() {
pipesService.createPipe("my-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
Pipe pipe = pipesService.describePipe("my-pipe", "us-east-1");
assertEquals("my-pipe", pipe.getName());
}
@Test
void describePipeNotFoundThrows() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.describePipe("nonexistent", "us-east-1"));
assertEquals("NotFoundException", ex.getErrorCode());
assertEquals(404, ex.getHttpStatus());
}
@Test
void updatePipe() {
pipesService.createPipe("update-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
"original", DesiredState.RUNNING, null, null, null, null, null, "us-east-1");
Pipe updated = pipesService.updatePipe("update-pipe",
"arn:aws:sqs:us-east-1:000000000000:new-target",
null, "updated desc", DesiredState.STOPPED, null, null, null, null, "us-east-1");
assertEquals("arn:aws:sqs:us-east-1:000000000000:new-target", updated.getTarget());
assertEquals("updated desc", updated.getDescription());
assertEquals(DesiredState.STOPPED, updated.getDesiredState());
assertEquals(PipeState.STOPPED, updated.getCurrentState());
}
@Test
void deletePipe() {
pipesService.createPipe("del-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
pipesService.deletePipe("del-pipe", "us-east-1");
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.describePipe("del-pipe", "us-east-1"));
assertEquals("NotFoundException", ex.getErrorCode());
}
@Test
void deleteNonexistentPipeThrows() {
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.deletePipe("ghost", "us-east-1"));
assertEquals("NotFoundException", ex.getErrorCode());
}
@Test
void listPipes() {
pipesService.createPipe("pipe-a",
"arn:aws:sqs:us-east-1:000000000000:source-a",
"arn:aws:sqs:us-east-1:000000000000:target-a",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.RUNNING, null, null, null, null, null, "us-east-1");
pipesService.createPipe("pipe-b",
"arn:aws:sqs:us-east-1:000000000000:source-b",
"arn:aws:sqs:us-east-1:000000000000:target-b",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.STOPPED, null, null, null, null, null, "us-east-1");
List<Pipe> all = pipesService.listPipes(null, null, null, null, null, "us-east-1");
assertEquals(2, all.size());
List<Pipe> filtered = pipesService.listPipes("pipe-a", null, null, null, null, "us-east-1");
assertEquals(1, filtered.size());
assertEquals("pipe-a", filtered.get(0).getName());
}
@Test
void listPipesFilterByDesiredState() {
pipesService.createPipe("running-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.RUNNING, null, null, null, null, null, "us-east-1");
pipesService.createPipe("stopped-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.STOPPED, null, null, null, null, null, "us-east-1");
List<Pipe> running = pipesService.listPipes(null, null, null, DesiredState.RUNNING, null, "us-east-1");
assertEquals(1, running.size());
assertEquals("running-pipe", running.get(0).getName());
}
@Test
void startPipe() {
pipesService.createPipe("start-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.STOPPED, null, null, null, null, null, "us-east-1");
Pipe pipe = pipesService.startPipe("start-pipe", "us-east-1");
assertEquals(DesiredState.RUNNING, pipe.getDesiredState());
assertEquals(PipeState.RUNNING, pipe.getCurrentState());
}
@Test
void stopPipe() {
pipesService.createPipe("stop-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, DesiredState.RUNNING, null, null, null, null, null, "us-east-1");
Pipe pipe = pipesService.stopPipe("stop-pipe", "us-east-1");
assertEquals(DesiredState.STOPPED, pipe.getDesiredState());
assertEquals(PipeState.STOPPED, pipe.getCurrentState());
}
@Test
void tagResource() {
Pipe pipe = pipesService.createPipe("tag-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
pipesService.tagResource("us-east-1", pipe.getArn(), Map.of("team", "platform"));
Map<String, String> tags = pipesService.listTags("us-east-1", pipe.getArn());
assertEquals("platform", tags.get("team"));
}
@Test
void untagResource() {
Pipe pipe = pipesService.createPipe("untag-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, Map.of("a", "1", "b", "2"), "us-east-1");
pipesService.untagResource("us-east-1", pipe.getArn(), List.of("a"));
Map<String, String> tags = pipesService.listTags("us-east-1", pipe.getArn());
assertFalse(tags.containsKey("a"));
assertEquals("2", tags.get("b"));
}
@Test
void regionIsolation() {
pipesService.createPipe("region-pipe",
"arn:aws:sqs:us-east-1:000000000000:source",
"arn:aws:sqs:us-east-1:000000000000:target",
"arn:aws:iam::000000000000:role/role",
null, null, null, null, null, null, null, "us-east-1");
AwsException ex = assertThrows(AwsException.class, () ->
pipesService.describePipe("region-pipe", "eu-west-1"));
assertEquals("NotFoundException", ex.getErrorCode());
}
}