Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STORAGE-2798 Updated B2StorageClientWebifierImpl methods to improve extensibility #205

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog
## [Unreleased] - TBD
### Changed
Updated `downloadByName()` and `downloadById()` to use their respective `getDownloadByNameUrl()` and
`getDownloadByIdUrl()` methods for improved extensibility

## [6.3.0] - 2024-11-08
### Added
* Fixed `B2StorageClient.deleteAllFilesInBucket` so it uses `fileVersions` instead of `fileNames`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void downloadById(B2AccountAuthorization accountAuth,
B2DownloadByIdRequest request,
B2ContentSink handler) throws B2Exception {
downloadGuts(accountAuth,
makeDownloadByIdUrl(accountAuth, request),
getDownloadByIdUrl(accountAuth, request),
request.getRange(),
request.getServerSideEncryption(),
handler);
Expand All @@ -505,7 +505,7 @@ public void downloadByName(B2AccountAuthorization accountAuth,
B2DownloadByNameRequest request,
B2ContentSink handler) throws B2Exception {
downloadGuts(accountAuth,
makeDownloadByNameUrl(accountAuth, request.getBucketName(), request.getFileName(), request),
getDownloadByNameUrl(accountAuth, request),
request.getRange(),
request.getServerSideEncryption(),
handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -1190,7 +1191,9 @@ public void testDownloadById() throws B2Exception {
final B2DownloadByIdRequest request = B2DownloadByIdRequest
.builder(fileId(1))
.build();
webifier.downloadById(ACCOUNT_AUTH, request, noopContentHandler);
final B2StorageClientWebifierImpl webifierSpy = spy(webifier);
webifierSpy.downloadById(ACCOUNT_AUTH, request, noopContentHandler);
verify(webifierSpy).getDownloadByIdUrl(ACCOUNT_AUTH, request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... I think this tests that getDownloadByIdUrl is called but my brain is wondering how useful this verify actually is beyond that. isn't that just an implementation detail? how does verifying it actually tell us more about whether downloadById is working as designed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that the combination of the verify and the assertion in the test would test that downloadById() is working as designed.

The verify checks that the getDownloadByIdUrl() is being called, which is an implementation detail, but an important one as that was the PR change

This verify alone doesn't test that the method is working properly however along with the assertion that the value from the verify call (expectedUrl) is the same as the one being passed to the web client call, we test that we call the right thing and that the right thing is passed.


webApiClient.check("getContent.\n" +
"url:\n" +
Expand All @@ -1201,7 +1204,7 @@ public void testDownloadById() throws B2Exception {
" X-Bz-Test-Mode: force_cap_exceeded\n"
);

assertEquals(expectedUrl, webifier.getDownloadByIdUrl(ACCOUNT_AUTH, request));
assertEquals(expectedUrl, webifierSpy.getDownloadByIdUrl(ACCOUNT_AUTH, request));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to use the spy'ed object?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to be. Is it a good practice to only use the spy reference when using Mockito calls and the non spy in cases like this? I was thinking it might be less confusing if using the same spy reference throughout the code instead of mixing. Don't mind either way. I'll change it back


checkRequestCategory(OTHER, w -> w.downloadById(ACCOUNT_AUTH, request, noopContentHandler));
}
Expand Down Expand Up @@ -1303,7 +1306,9 @@ public void testDownloadByName() throws B2Exception {
final B2DownloadByNameRequest request = B2DownloadByNameRequest
.builder(bucketName(1), fileName(1))
.build();
webifier.downloadByName(ACCOUNT_AUTH, request, noopContentHandler);
final B2StorageClientWebifierImpl webifierSpy = spy(webifier);
webifierSpy.downloadByName(ACCOUNT_AUTH, request, noopContentHandler);
verify(webifierSpy).getDownloadByNameUrl(ACCOUNT_AUTH, request);

webApiClient.check("getContent.\n" +
"url:\n" +
Expand All @@ -1313,7 +1318,7 @@ public void testDownloadByName() throws B2Exception {
" User-Agent: SecretAgentMan/3.19.28\n" +
" X-Bz-Test-Mode: force_cap_exceeded\n"
);
assertEquals(expectedUrl, webifier.getDownloadByNameUrl(ACCOUNT_AUTH, request));
assertEquals(expectedUrl, webifierSpy.getDownloadByNameUrl(ACCOUNT_AUTH, request));

checkRequestCategory(OTHER, w -> w.downloadByName(ACCOUNT_AUTH, request, noopContentHandler));
}
Expand Down
Loading