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

fix: FakeStorageRpc#list to filtering the files by bucket and prefix #208

Merged
merged 2 commits into from Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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)) {
athakor marked this conversation as resolved.
Show resolved Hide resolved
values.add(so);
}
}
values.addAll(folders.values());

Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down