Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(rds): expand query handler and service unit coverage (#362)

TiM34cc0903a84a
diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
index 3c5aa2c7a8..c2dc5a737f 100644
--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
@@ -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() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
index 222b98ef14..c9968507aa 100644
--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
@@ -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"));
+ }
}