mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(redshift-serverless): add UpdateSnapshot (#5537)
Change a snapshot's retentionPeriod (-1 for indefinite) with the same validation as CreateSnapshot; an omitted period leaves the snapshot unchanged.
This commit is contained in:
1 parent
dd0f40fcbb
commit
a95b01020b
8 files changed
+104
-1
No files matched your search
+8
@@ -230,6 +230,14 @@ class RedshiftServerlessIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
call("UpdateSnapshot", "{\"snapshotName\":\"snap-life\",\"retentionPeriod\":30}")
|
||||
.statusCode(200)
|
||||
.body("snapshot.snapshotRetentionPeriod", equalTo(30))
|
||||
.body("snapshot.snapshotRemainingDays", equalTo(30));
|
||||
call("UpdateSnapshot", "{\"snapshotName\":\"snap-life\",\"retentionPeriod\":0}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
call("ListSnapshots", "{\"namespaceName\":\"snap-life-ns\",\"maxResults\":1}")
|
||||
.statusCode(200)
|
||||
.body("snapshots.snapshotName", hasItem("snap-life"));
|
||||
|
||||
+26
@@ -76,6 +76,9 @@ class RedshiftServerlessJsonHandlerTest {
|
||||
iamDbUserResolver = mock(RedshiftIamDbUserResolver.class);
|
||||
when(iamDbUserResolver.resolveDbUser("AUTH")).thenReturn("IAM:alice");
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, org.mockito.Mockito.RETURNS_DEEP_STUBS);
|
||||
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-snapshots.json"),
|
||||
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
when(config.storage().persistentPath()).thenReturn(System.getProperty("java.io.tmpdir"));
|
||||
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-usagelimits.json"),
|
||||
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
|
||||
@@ -472,6 +475,29 @@ class RedshiftServerlessJsonHandlerTest {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSnapshotReturnsTheUpdatedSnapshotAndRejectsABadRetention() {
|
||||
create("upd-handler-ns");
|
||||
body(handler.handle("CreateSnapshot",
|
||||
parse("{\"snapshotName\":\"upd-handler\",\"namespaceName\":\"upd-handler-ns\",\"retentionPeriod\":7}"),
|
||||
REGION));
|
||||
|
||||
JsonNode updated = body(handler.handle("UpdateSnapshot",
|
||||
parse("{\"snapshotName\":\"upd-handler\",\"retentionPeriod\":45}"), REGION)).get("snapshot");
|
||||
assertEquals("upd-handler", updated.get("snapshotName").textValue());
|
||||
assertEquals(45, updated.get("snapshotRetentionPeriod").intValue());
|
||||
assertEquals(45, updated.get("snapshotRemainingDays").intValue());
|
||||
|
||||
JsonNode indefinite = body(handler.handle("UpdateSnapshot",
|
||||
parse("{\"snapshotName\":\"upd-handler\",\"retentionPeriod\":-1}"), REGION)).get("snapshot");
|
||||
assertTrue(indefinite.path("snapshotRetentionPeriod").isMissingNode());
|
||||
|
||||
assertEquals(400, handler.handle("UpdateSnapshot",
|
||||
parse("{\"snapshotName\":\"upd-handler\",\"retentionPeriod\":0}"), REGION).getStatus());
|
||||
assertEquals(400, handler.handle("UpdateSnapshot",
|
||||
parse("{\"snapshotName\":\"missing-snap\",\"retentionPeriod\":5}"), REGION).getStatus());
|
||||
}
|
||||
|
||||
private JsonNode body(Response response) {
|
||||
assertEquals(200, response.getStatus(), "expected a successful response, got " + response.getEntity());
|
||||
return mapper.valueToTree(response.getEntity());
|
||||
|
||||
+43
@@ -1026,6 +1026,49 @@ class RedshiftServerlessServiceTest {
|
||||
assertEquals("ResourceNotFoundException", missing.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSnapshotChangesOnlyTheRetentionPeriod() {
|
||||
create("upd-snap-ns");
|
||||
service.createSnapshot("upd-snap", "upd-snap-ns", 30, Map.of("env", "dev"), REGION);
|
||||
|
||||
RedshiftServerlessSnapshot updated = service.updateSnapshot("upd-snap", 90, REGION);
|
||||
|
||||
assertEquals(90, updated.getRetentionPeriod());
|
||||
assertEquals(90, service.getSnapshot("upd-snap", REGION).getRetentionPeriod());
|
||||
assertEquals("upd-snap-ns", updated.getNamespaceName());
|
||||
assertEquals(Map.of("env", "dev"), service.listTagsForResource(updated.getSnapshotArn(), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSnapshotAcceptsIndefiniteRetentionAndLeavesAnOmittedPeriodAlone() {
|
||||
create("upd-indef-ns");
|
||||
service.createSnapshot("upd-indef", "upd-indef-ns", 30, null, REGION);
|
||||
|
||||
assertEquals(30, service.updateSnapshot("upd-indef", null, REGION).getRetentionPeriod());
|
||||
assertNull(service.updateSnapshot("upd-indef", -1, REGION).getRetentionPeriod());
|
||||
assertNull(service.getSnapshot("upd-indef", REGION).getRetentionPeriod());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSnapshotRejectsAnInvalidRetentionWithoutChangingTheSnapshot() {
|
||||
create("upd-bad-ns");
|
||||
service.createSnapshot("upd-bad", "upd-bad-ns", 30, null, REGION);
|
||||
|
||||
for (int bad : new int[] {0, 3654, -2}) {
|
||||
AwsException rejected = assertThrows(AwsException.class,
|
||||
() -> service.updateSnapshot("upd-bad", bad, REGION));
|
||||
assertEquals("ValidationException", rejected.getErrorCode());
|
||||
}
|
||||
assertEquals(30, service.getSnapshot("upd-bad", REGION).getRetentionPeriod());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSnapshotOfAnUnknownSnapshotIsNotFound() {
|
||||
AwsException missing = assertThrows(AwsException.class, () -> service.updateSnapshot("nope-snap", 5, REGION));
|
||||
assertEquals("ResourceNotFoundException", missing.getErrorCode());
|
||||
assertThrows(AwsException.class, () -> service.updateSnapshot(null, 5, REGION));
|
||||
}
|
||||
|
||||
private Namespace create(String namespaceName) {
|
||||
return service.createNamespace(namespaceName, "admin", null, null, null, null, null, Map.of(), REGION);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user