Skip to content
Permalink
Browse files
fix: FakeStorageRpc#list to filtering the files by bucket and prefix (#…
…208)

* fix: list method of FakeStorageRpc

* fix: list method of FakeStorageRpc
  • Loading branch information
athakor committed Sep 9, 2020
1 parent 33fdc31 commit 21f606eca67b1c8a471ee28f7e2dd3851a0c493e
@@ -151,7 +151,9 @@ public Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?>
continue;
}
so.setSize(size(so));
values.add(so);
if (so.getBucket().equals(bucket)) {
values.add(so);
}
}
values.addAll(folders.values());

@@ -26,6 +26,7 @@
import static org.junit.Assert.assertSame;

import com.google.api.client.http.HttpResponseException;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
@@ -37,8 +38,10 @@
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem;
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider;
import com.google.cloud.storage.contrib.nio.CloudStoragePath;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
import com.google.cloud.storage.testing.RemoteStorageHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
@@ -62,6 +65,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@@ -1074,6 +1078,32 @@ public void testCopyWithDifferentProvider() throws IOException {
assertNotEquals(sourceFileSystem.config(), targetFileSystem.config());
}

@Test
public void testListObject() throws IOException {
String firstBucket = "first-bucket-" + UUID.randomUUID().toString();
String secondBucket = "second-bucket" + UUID.randomUUID().toString();
Storage localStorageService = LocalStorageHelper.customOptions(true).getService();
fillFile(localStorageService, firstBucket, "object", SML_SIZE);
fillFile(localStorageService, firstBucket, "test-object", SML_SIZE);
fillFile(localStorageService, secondBucket, "test-object", SML_SIZE);

// Listing objects from first bucket without prefix.
List<Blob> objects = Lists.newArrayList(localStorageService.list(firstBucket).getValues());
assertThat(objects.size()).isEqualTo(2);

// Listing objects from first bucket with prefix.
objects =
Lists.newArrayList(
localStorageService
.list(firstBucket, Storage.BlobListOption.prefix("test-"))
.getValues());
assertThat(objects.size()).isEqualTo(1);

// Listing objects from second bucket.
objects = Lists.newArrayList(localStorageService.list(secondBucket).getValues());
assertThat(objects.size()).isEqualTo(1);
}

private CloudStorageFileSystem getTestBucket() throws IOException {
// in typical usage we use the single-argument version of forBucket
// and rely on the user being logged into their project with the

0 comments on commit 21f606e

Please sign in to comment.