Skip to content

Commit

Permalink
DEV-27776 deleteAllFilesInBucket use fileVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
brett-backblaze authored and nbehrens-bz committed Oct 29, 2024
1 parent f056abc commit 083c2da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ default void deleteFileVersion(String fileName,
* file versions have been deleted (if any) and which haven't (if any).
*/
default void deleteAllFilesInBucket(String bucketId) throws B2Exception {
for (B2FileVersion fileVersion: fileNames(bucketId)) {
for (B2FileVersion fileVersion: fileVersions(bucketId)) {
deleteFileVersion(fileVersion);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,24 @@ public void testDeleteFileVersion() throws B2Exception {

}

@Test
public void testDeleteAllFilesInBucket() throws B2Exception {
final B2ListFileVersionsRequest request = B2ListFileVersionsRequest.builder(bucketId(1)).setMaxFileCount(1000).build();
final List<B2FileVersion> versions = new ArrayList<>();
for (int i = 0; i < 10; i++) {
versions.add(makeVersion(i, i));
}
final B2ListFileVersionsResponse response = new B2ListFileVersionsResponse(versions, null, null);
when(webifier.listFileVersions(anyObject(), eq(request))).thenReturn(response);

client.deleteAllFilesInBucket(bucketId(1));

for (B2FileVersion version : versions) {
final B2DeleteFileVersionRequest deleteRequest = B2DeleteFileVersionRequest.builder(version.getFileName(), version.getFileId()).build();
verify(webifier, times(1)).deleteFileVersion(anyObject(), eq(deleteRequest));
}
}

@Test
public void testGetDownloadAuthorization() throws B2Exception {
final B2DownloadAuthorization downloadAuth = new B2DownloadAuthorization(bucketId(1), FILE_PREFIX, "downloadAuthToken");
Expand Down

0 comments on commit 083c2da

Please sign in to comment.