Skip to content

Commit

Permalink
feat: add delimiter BlobListOption (#102)
Browse files Browse the repository at this point in the history
* feat: add delimiter BlobListOption

* feat: added testcase for delemiter method

* feat: fix review changes

* build: fix build
  • Loading branch information
athakor committed Feb 14, 2020
1 parent bb7a62c commit b30a675
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Expand Up @@ -1003,6 +1003,16 @@ public static BlobListOption currentDirectory() {
return new BlobListOption(StorageRpc.Option.DELIMITER, true);
}

/**
* Returns an option to set a delimiter.
*
* @param delimiter generally '/' is the one used most often, but you can used other delimiters
* as well.
*/
public static BlobListOption delimiter(String delimiter) {
return new BlobListOption(StorageRpc.Option.DELIMITER, delimiter);
}

/**
* Returns an option to define the billing user project. This option is required by buckets with
* `requester_pays` flag enabled to assign operation costs.
Expand Down
Expand Up @@ -1594,9 +1594,11 @@ private static <T> void addToOptionMap(
Object prev = temp.put(option.getRpcOption(), option.getValue());
checkArgument(prev == null, "Duplicate option %s", option);
}
Boolean value = (Boolean) temp.remove(DELIMITER);
if (Boolean.TRUE.equals(value)) {
if (Boolean.TRUE.equals(temp.get(DELIMITER))) {
temp.remove(DELIMITER);
temp.put(DELIMITER, PATH_DELIMITER);
} else if (null != temp.get(DELIMITER)) {
temp.put(DELIMITER, temp.get(DELIMITER));
}
if (useAsSource) {
addToOptionMap(IF_GENERATION_MATCH, IF_SOURCE_GENERATION_MATCH, generation, temp);
Expand Down
Expand Up @@ -1166,6 +1166,23 @@ public void testListBlobsCurrentDirectory() {
assertArrayEquals(blobList.toArray(), Iterables.toArray(page.getValues(), Blob.class));
}

@Test
public void testListBlobsDelimiter() {
String cursor = "cursor";
String delimiter = "/";
Map<StorageRpc.Option, ?> options = ImmutableMap.of(StorageRpc.Option.DELIMITER, delimiter);
ImmutableList<BlobInfo> blobInfoList = ImmutableList.of(BLOB_INFO1, BLOB_INFO2);
Tuple<String, Iterable<com.google.api.services.storage.model.StorageObject>> result =
Tuple.of(cursor, Iterables.transform(blobInfoList, BlobInfo.INFO_TO_PB_FUNCTION));
EasyMock.expect(storageRpcMock.list(BUCKET_NAME1, options)).andReturn(result);
EasyMock.replay(storageRpcMock);
initializeService();
ImmutableList<Blob> blobList = ImmutableList.of(expectedBlob1, expectedBlob2);
Page<Blob> page = storage.list(BUCKET_NAME1, Storage.BlobListOption.delimiter(delimiter));
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(blobList.toArray(), Iterables.toArray(page.getValues(), Blob.class));
}

@Test
public void testUpdateBucket() {
BucketInfo updatedBucketInfo = BUCKET_INFO1.toBuilder().setIndexPage("some-page").build();
Expand Down

0 comments on commit b30a675

Please sign in to comment.