mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(rds): expand query handler and service unit coverage (#362)
* test(rds): expand query handler and service unit coverage RdsQueryHandlerTest additions: - describe DB instances with unknown filter falls back to unfiltered list - CreateDBInstance with invalid AllocatedStorage falls back to default and pins engine-version default resolution - unknown engine gets generic default version - ModifyDBParameterGroup ignores parameters that are missing a value - DescribeDBParameters rejects missing DBParameterGroupName (400) - unsupported operation returns UnsupportedOperation query error RdsServiceTest additions: - modifyDbInstance with blank password does not overwrite the existing master password - modifyDbInstance can toggle IAM authentication without changing password - deleteDbCluster fails with InvalidDBClusterStateFault when cluster still has member instances Adds src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker pinning to mock-maker-subclass so the new ArgumentMatchers.eq usage works on JDK 21 without the inline mock maker. Pure unit tests, no container dependency. * test(rds): address review findings for query handler tests Drop mock-maker-subclass config that broke InitializationHooksRunnerTest (Mockito inline mock-maker is the correct default for Java 25 final class mocking). Fix unknownEngine test to verify the realistic error path: handler defaults version to "1.0" for unknown engines, service rejects with InvalidParameterValue, handler wraps into 400 query error. Full suite 1842/0 green (clean build).
This commit is contained in:
2 files changed
+127
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbCluster;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbInstance;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
|
||||
@@ -14,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -114,6 +116,18 @@ class RdsQueryHandlerTest {
|
||||
verify(service).listDbClusters("mycluster");
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_unknownFilterFallsBackToUnfilteredList() {
|
||||
when(service.listDbInstances(null)).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("Filters.Filter.1.Name", "engine");
|
||||
p.add("Filters.Filter.1.Values.Value.1", "postgres");
|
||||
handler.handle("DescribeDBInstances", p);
|
||||
|
||||
verify(service).listDbInstances(null);
|
||||
}
|
||||
|
||||
// ──────────────────────────── DBParameterGroups XML tag ──────────────────────
|
||||
|
||||
@Test
|
||||
@@ -128,6 +142,79 @@ class RdsQueryHandlerTest {
|
||||
assertFalse(body.contains("<member><DBParameterGroupName>"), "Did not expect <member> wrapping DBParameterGroup");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstance_invalidAllocatedStorageFallsBackToDefaultAndEngineVersionDefaults() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq("admin"), eq("secret"), eq("dbname"), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null)))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "postgres");
|
||||
p.add("MasterUsername", "admin");
|
||||
p.add("MasterUserPassword", "secret");
|
||||
p.add("DBName", "dbname");
|
||||
p.add("AllocatedStorage", "not-a-number");
|
||||
handler.handle("CreateDBInstance", p);
|
||||
|
||||
verify(service).createDbInstance("mydb", "postgres", "16.3",
|
||||
"admin", "secret", "dbname", "db.t3.micro", 20, false, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstance_unknownEngineReturnsInvalidParameterValue() {
|
||||
// Handler defaults version to "1.0" for unknown engines, then the service
|
||||
// rejects the engine. Verify the full error path: version defaulting +
|
||||
// AwsException wrapping into a 400 query error.
|
||||
when(service.createDbInstance(eq("mydb"), eq("oracle"), eq("1.0"),
|
||||
eq(null), eq(null), eq(null), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null)))
|
||||
.thenThrow(new AwsException("InvalidParameterValue",
|
||||
"Unsupported engine: oracle. Supported: postgres, mysql, mariadb.", 400));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "oracle");
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbParameterGroup_ignoresParametersWithoutValue() {
|
||||
DbParameterGroup group = new DbParameterGroup("pg1", "postgres15", "test group");
|
||||
when(service.modifyDbParameterGroup(eq("pg1"), eq(java.util.Map.of("max_connections", "200"))))
|
||||
.thenReturn(group);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBParameterGroupName", "pg1");
|
||||
p.add("Parameters.member.1.ParameterName", "max_connections");
|
||||
p.add("Parameters.member.1.ParameterValue", "200");
|
||||
p.add("Parameters.member.2.ParameterName", "ignored_without_value");
|
||||
handler.handle("ModifyDBParameterGroup", p);
|
||||
|
||||
verify(service).modifyDbParameterGroup("pg1", java.util.Map.of("max_connections", "200"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbParameters_requiresParameterGroupName() {
|
||||
Response response = handler.handle("DescribeDBParameters", params());
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("DBParameterGroupName is required."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedOperationReturnsQueryError() {
|
||||
Response response = handler.handle("NoSuchAction", params());
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("UnsupportedOperation"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private static MultivaluedMap<String, String> params() {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.rds.model.DatabaseEngine;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbCluster;
|
||||
import io.github.hectorvent.floci.services.rds.container.RdsContainerHandle;
|
||||
import io.github.hectorvent.floci.services.rds.container.RdsContainerManager;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbInstance;
|
||||
@@ -76,4 +79,41 @@ class RdsServiceTest {
|
||||
Collection<DbInstance> result = rdsService.listDbInstances("nonexistent");
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceBlankPasswordDoesNotOverwriteExistingPassword() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "original-password", "dbname", "db.t3.micro",
|
||||
20, false, null, null);
|
||||
|
||||
DbInstance modified = rdsService.modifyDbInstance("mydb", " ", null);
|
||||
|
||||
assertEquals("original-password", modified.getMasterPassword());
|
||||
assertFalse(modified.isIamDatabaseAuthenticationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceCanToggleIamWithoutChangingPassword() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "original-password", "dbname", "db.t3.micro",
|
||||
20, false, null, null);
|
||||
|
||||
DbInstance modified = rdsService.modifyDbInstance("mydb", null, true);
|
||||
|
||||
assertEquals("original-password", modified.getMasterPassword());
|
||||
assertTrue(modified.isIamDatabaseAuthenticationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDbClusterFailsWhenMembersRemain() {
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster1", "postgres", "13",
|
||||
"admin", "password", "dbname", false, null);
|
||||
cluster.getDbClusterMembers().add("instance-1");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteDbCluster("cluster1"));
|
||||
|
||||
assertEquals("InvalidDBClusterStateFault", exception.getErrorCode());
|
||||
assertTrue(exception.getMessage().contains("still has DB instances"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user