Make grpc ListMedia limit optional

This commit is contained in:
Ravi Khadiwala authored and ravi-signal committed 2026-08-05 13:20:09 -05:00
1 parent cbc89f541c
commit e4b09112f1
7 files changed
+33 -11

No files matched your search

@@ -667,7 +667,7 @@ public class BackupManagerTest {
Optional.of("newCursor")
)));
final BackupManager.ListMediaResult result = backupManager.list(backupUser, cursor, 17);
final BackupManager.ListMediaResult result = backupManager.list(backupUser, cursor, Optional.of(17));
assertThat(result.media()).hasSize(1);
assertThat(result.media().getFirst().cdn()).isEqualTo(13);
assertThat(result.media().getFirst().key()).isEqualTo(
@@ -562,7 +562,7 @@ public class ArchiveControllerTest {
final Optional<String> expectedCursor = cursorProvided ? Optional.of("myCursor") : Optional.empty();
final Optional<String> returnedCursor = cursorReturned ? Optional.of("newCursor") : Optional.empty();
when(backupManager.list(any(), eq(expectedCursor), eq(17)))
when(backupManager.list(any(), eq(expectedCursor), eq(Optional.of(17))))
.thenReturn(new BackupManager.ListMediaResult(
List.of(new BackupManager.StorageDescriptorWithLength(1, mediaId, 100)),
returnedCursor
@@ -11,6 +11,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.protobuf.ByteString;
@@ -290,7 +291,7 @@ class BackupsAnonymousGrpcServiceTest extends
final int limit = 17;
when(backupManager.list(any(), eq(expectedCursor), eq(limit)))
when(backupManager.list(any(), eq(expectedCursor), eq(Optional.of(limit))))
.thenReturn(new BackupManager.ListMediaResult(
List.of(new BackupManager.StorageDescriptorWithLength(1, mediaId, 100)),
returnedCursor));
@@ -463,6 +464,21 @@ class BackupsAnonymousGrpcServiceTest extends
.build()));
}
@Test
void listMediaUnsetLimit() throws BackupException {
when(backupManager.list(any(), any(), eq(Optional.empty())))
.thenReturn(new BackupManager.ListMediaResult(List.of(), Optional.empty()));
// should be able to list without setting a limit
final ListMediaResponse response = unauthenticatedServiceStub().listMedia(
ListMediaRequest.newBuilder()
.setSignedPresentation(signedPresentation(presentation))
.build());
assertThat(response.hasListResult()).isTrue();
verify(backupManager).list(any(), any(), eq(Optional.empty()));
}
private static AuthenticatedBackupUser backupUser(final byte[] backupId, final BackupCredentialType credentialType,
final BackupLevel backupLevel) {