Skip to content

Commit

Permalink
fix: update expected error message when checking requester pays status
Browse files Browse the repository at this point in the history
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.

Refs: googleapis#824
  • Loading branch information
lbergelson committed Mar 1, 2022
1 parent e880f80 commit 35683e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
@ThreadSafe
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 @@ -967,7 +969,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 @@ -288,7 +288,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 @@ -342,14 +342,16 @@ 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 35683e1

Please sign in to comment.