mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(appconfig): implement ListDeployments (#3749)
* feat(appconfig): add deployment listing service * feat(appconfig): expose ListDeployments * docs(appconfig): document ListDeployments * chore(appconfig): clean controller imports * fix(appconfig): make deployment pagination cursor-based
This commit is contained in:
1 parent
66bcdaf675
commit
d624988ff8
6 files changed
+415
-9
No files matched your search
+88
@@ -28,6 +28,8 @@ class AppConfigIntegrationTest {
|
||||
private static String emptyAppId;
|
||||
private static String emptyEnvId;
|
||||
private static String emptyProfileId;
|
||||
private static String deploymentNextToken;
|
||||
private static String secondDeploymentNextToken;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
@@ -372,6 +374,92 @@ class AppConfigIntegrationTest {
|
||||
.body("DeploymentStrategyId", equalTo("AppConfig.AllAtOnce"));
|
||||
}
|
||||
|
||||
@Test @Order(39)
|
||||
void listDeploymentsReturnsDescendingFirstPage() {
|
||||
deploymentNextToken = given()
|
||||
.queryParam("max_results", 1)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items.size()", equalTo(1))
|
||||
.body("Items[0].DeploymentNumber", equalTo(3))
|
||||
.body("Items[0].ConfigurationProfileId", equalTo(profileId))
|
||||
.body("Items[0].ConfigurationVersion", equalTo("1"))
|
||||
.body("Items[0].State", equalTo("COMPLETE"))
|
||||
.body("Items[0].ConfigurationName", equalTo("test-profile"))
|
||||
.body("Items[0].Type", equalTo("AWS.Freeform"))
|
||||
.extract().path("NextToken");
|
||||
}
|
||||
|
||||
@Test @Order(40)
|
||||
void listDeploymentsReturnsSecondPageAndConsumesFinalToken() {
|
||||
secondDeploymentNextToken = given()
|
||||
.queryParam("max_results", 1)
|
||||
.queryParam("next_token", deploymentNextToken)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items.size()", equalTo(1))
|
||||
.body("Items[0].DeploymentNumber", equalTo(2))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
given()
|
||||
.queryParam("max_results", 1)
|
||||
.queryParam("next_token", secondDeploymentNextToken)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items[0].DeploymentNumber", equalTo(1))
|
||||
.body("NextToken", nullValue());
|
||||
|
||||
given()
|
||||
.queryParam("next_token", secondDeploymentNextToken)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test @Order(41)
|
||||
void listDeploymentsRejectsInvalidPagination() {
|
||||
given()
|
||||
.queryParam("max_results", 0)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
|
||||
given()
|
||||
.queryParam("max_results", 51)
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
|
||||
given()
|
||||
.queryParam("max_results", "not-a-number")
|
||||
.when().get("/applications/" + appId + "/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test @Order(42)
|
||||
void listDeploymentsRejectsMissingResources() {
|
||||
given()
|
||||
.when().get("/applications/missing-app/environments/" + envId + "/deployments")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given()
|
||||
.when().get("/applications/" + appId + "/environments/missing-env/deployments")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Application tagging ────────────────────────────
|
||||
|
||||
@Test @Order(17)
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Application;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Environment;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.DeploymentSummary;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AppConfigServiceTest {
|
||||
private AccountAwareStorageBackend<Application> applicationStore;
|
||||
private AccountAwareStorageBackend<Environment> environmentStore;
|
||||
private AccountAwareStorageBackend<Deployment> deploymentStore;
|
||||
private AppConfigService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
applicationStore = mock(AccountAwareStorageBackend.class);
|
||||
environmentStore = mock(AccountAwareStorageBackend.class);
|
||||
deploymentStore = mock(AccountAwareStorageBackend.class);
|
||||
Map<String, Deployment> deployments = new HashMap<>();
|
||||
doAnswer(invocation -> {
|
||||
deployments.put(invocation.getArgument(0, String.class), invocation.getArgument(1, Deployment.class));
|
||||
return null;
|
||||
}).when(deploymentStore).put(anyString(), any(Deployment.class));
|
||||
when(deploymentStore.scan(any())).thenAnswer(invocation -> List.copyOf(deployments.values()));
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
doAnswer(invocation -> switch (invocation.getArgument(1, String.class)) {
|
||||
case "appconfig-applications.json" -> applicationStore;
|
||||
case "appconfig-environments.json" -> environmentStore;
|
||||
case "appconfig-deployments.json" -> deploymentStore;
|
||||
default -> mock(AccountAwareStorageBackend.class);
|
||||
}).when(storageFactory).create(anyString(), anyString(), any(TypeReference.class));
|
||||
|
||||
Application application = new Application();
|
||||
application.setId("app");
|
||||
applicationStore.put("app", application);
|
||||
when(applicationStore.get("app")).thenReturn(Optional.of(application));
|
||||
Environment environment = new Environment();
|
||||
environment.setId("env");
|
||||
environment.setApplicationId("app");
|
||||
environmentStore.put("env", environment);
|
||||
when(environmentStore.get("env")).thenReturn(Optional.of(environment));
|
||||
service = new AppConfigService(storageFactory, mock(EmulatorConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDeploymentsReturnsDescendingPages() {
|
||||
deploymentStore.put("app::env::1", deployment("app", "env", 1));
|
||||
deploymentStore.put("app::env::2", deployment("app", "env", 2));
|
||||
|
||||
AppConfigService.DeploymentPage page = service.listDeployments("app", "env", 1, null);
|
||||
|
||||
assertEquals(List.of(2), page.items().stream().map(DeploymentSummary::getDeploymentNumber).toList());
|
||||
assertNotNull(page.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDeploymentsCursorSurvivesNewDeployment() {
|
||||
deploymentStore.put("app::env::1", deployment("app", "env", 1));
|
||||
deploymentStore.put("app::env::2", deployment("app", "env", 2));
|
||||
deploymentStore.put("app::env::3", deployment("app", "env", 3));
|
||||
|
||||
AppConfigService.DeploymentPage firstPage = service.listDeployments("app", "env", 1, null);
|
||||
deploymentStore.put("app::env::4", deployment("app", "env", 4));
|
||||
|
||||
AppConfigService.DeploymentPage secondPage = service.listDeployments(
|
||||
"app", "env", 1, firstPage.nextToken());
|
||||
|
||||
assertEquals(List.of(2), secondPage.items().stream()
|
||||
.map(DeploymentSummary::getDeploymentNumber).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDeploymentsFiltersApplicationAndEnvironment() {
|
||||
deploymentStore.put("app::env::1", deployment("app", "env", 1));
|
||||
deploymentStore.put("other::env::2", deployment("other", "env", 2));
|
||||
deploymentStore.put("app::other-env::3", deployment("app", "other-env", 3));
|
||||
|
||||
AppConfigService.DeploymentPage page = service.listDeployments("app", "env", null, null);
|
||||
|
||||
assertEquals(List.of(1), page.items().stream().map(DeploymentSummary::getDeploymentNumber).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDeploymentsRejectsInvalidPageSize() {
|
||||
assertThrows(RuntimeException.class, () -> service.listDeployments("app", "env", 0, null));
|
||||
assertThrows(RuntimeException.class, () -> service.listDeployments("app", "env", 51, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDeploymentsRejectsUnknownToken() {
|
||||
assertThrows(RuntimeException.class, () -> service.listDeployments("app", "env", 1, "unknown"));
|
||||
}
|
||||
|
||||
private static Deployment deployment(String applicationId, String environmentId, int number) {
|
||||
Deployment deployment = new Deployment();
|
||||
deployment.setApplicationId(applicationId);
|
||||
deployment.setEnvironmentId(environmentId);
|
||||
deployment.setDeploymentNumber(number);
|
||||
deployment.setConfigurationProfileId("profile");
|
||||
deployment.setConfigurationVersion("version");
|
||||
deployment.setDeploymentStrategyId("AppConfig.AllAtOnce");
|
||||
deployment.setState("COMPLETE");
|
||||
return deployment;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user