Skip to content

Commit

Permalink
Fix expected error message googleapis#824
Browse files Browse the repository at this point in the history
* Fix the expected error message that is tested when checking for requester pays buckets.
* The error message recieved when querying for requester pays status changed to include an 'a' which caused strict matching to fail.
* This fixes and standardizes the error message to use the same string for both the code and the tests.
  • Loading branch information
lbergelson committed Mar 1, 2022
1 parent bc329ba commit 2aec169
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
@AutoService(FileSystemProvider.class)
public final class CloudStorageFileSystemProvider extends FileSystemProvider {

public static final String BUCKET_IS_REQUESTER_PAYS_ERROR_MESSAGE = "Bucket is a requester pays bucket but no user project provided";
private Storage storage;
private final StorageOptions storageOptions;
// if non-null, we pay via this project.
Expand Down Expand Up @@ -971,7 +972,7 @@ public boolean requesterPays(String bucketName) {
Boolean isRP = storage.get(bucketName).requesterPays();
return isRP != null && isRP.booleanValue();
} catch (StorageException ex) {
if (ex.getCode() == 400 && ex.getMessage().contains("Bucket is requester pays")) {
if (ex.getCode() == 400 && ex.getMessage().contains(BUCKET_IS_REQUESTER_PAYS_ERROR_MESSAGE)) {
return true;
}
throw ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void innerTestCantCopyWithoutUserProject(
Assert.assertTrue(
description,
hex.getMessage()
.contains("Bucket is requester pays bucket but no user project provided"));
.contains(CloudStorageFileSystemProvider.BUCKET_IS_REQUESTER_PAYS_ERROR_MESSAGE));
} catch (StorageException ex) {
assertIsRequesterPaysException(description, ex);
}
Expand Down Expand Up @@ -319,14 +319,14 @@ private void assertIsRequesterPaysException(String message, StorageException ex)
Assert.assertEquals(message, ex.getCode(), 400);
Assert.assertTrue(
message,
ex.getMessage().contains("Bucket is requester pays bucket but no user project provided"));
ex.getMessage().contains(CloudStorageFileSystemProvider.BUCKET_IS_REQUESTER_PAYS_ERROR_MESSAGE));
}

private void assertIsRequesterPaysException(String message, IOException ioex) {
Assert.assertTrue(message, ioex.getMessage().startsWith("400"));
Assert.assertTrue(
message,
ioex.getMessage().contains("Bucket is requester pays bucket but no user project provided"));
ioex.getMessage().contains(CloudStorageFileSystemProvider.BUCKET_IS_REQUESTER_PAYS_ERROR_MESSAGE));
}
// End of tests related to the "requester pays" feature

Expand Down

0 comments on commit 2aec169

Please sign in to comment.