From b3ca39b237228013af8e067c676bf4fdb18b8756 Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Thu, 11 Apr 2024 10:53:19 -0700 Subject: [PATCH] add more tests --- .../ITTransferManagerSamples.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/com/example/storage/transfermanager/ITTransferManagerSamples.java b/samples/snippets/src/test/java/com/example/storage/transfermanager/ITTransferManagerSamples.java index 2a81c5fc47..192f8d425e 100644 --- a/samples/snippets/src/test/java/com/example/storage/transfermanager/ITTransferManagerSamples.java +++ b/samples/snippets/src/test/java/com/example/storage/transfermanager/ITTransferManagerSamples.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; +import com.google.cloud.storage.BlobId; import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.BucketInfo; import com.google.cloud.storage.Storage; @@ -26,7 +27,9 @@ import com.google.cloud.testing.junit4.StdOutCaptureRule; import com.google.common.collect.ImmutableList; import java.io.File; +import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.BeforeClass; @@ -55,6 +58,7 @@ public static void beforeClass() { for (BlobInfo blob : blobs) { storage.create(blob); } + } @Test @@ -64,14 +68,43 @@ public void uploadFiles() throws Exception { File tmpFile3 = File.createTempFile("file3", ".txt"); List files = ImmutableList.of(tmpFile.toPath(), tmpFile2.toPath(), tmpFile3.toPath()); - String bucketName = BUCKET; - UploadMany.uploadManyFiles(bucketName, files); + UploadMany.uploadManyFiles(BUCKET, files); String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String(); assertThat(snippetOutput.contains("file")).isTrue(); assertThat(snippetOutput.contains("file2")).isTrue(); assertThat(snippetOutput.contains("file3")).isTrue(); } + @Test + public void uploadDirectory() throws IOException { + TemporaryFolder tmpDirectory = new TemporaryFolder(); + File tmpFile = tmpDirectory.newFile("fileDirUpload.txt"); + File tmpFile2 = tmpDirectory.newFile("fileDirUpload2.txt"); + File tmpFile3 = tmpDirectory.newFile("fileDirUpload3.txt"); + UploadDirectory.uploadDirectoryContents(BUCKET, tmpDirectory.getRoot().toPath()); + String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String(); + assertThat(snippetOutput.contains("fileDirUpload.txt")).isTrue(); + assertThat(snippetOutput.contains("fileDirUpload2.txt")).isTrue(); + assertThat(snippetOutput.contains("fileDirUpload3.txt")).isTrue(); + } + + @Test + public void downloadBucket() { + String downloadFullBucketName = RemoteStorageHelper.generateBucketName(); + storage.create(BucketInfo.of(downloadFullBucketName)); + List bucketBlobs = Arrays.asList(BlobInfo.newBuilder(downloadFullBucketName, "bucketb1").build(), + BlobInfo.newBuilder(downloadFullBucketName, "bucketb2").build(), + BlobInfo.newBuilder(downloadFullBucketName, "bucketb3").build()); + for (BlobInfo blob : blobs) { + storage.create(blob); + } + DownloadBucket.downloadBucketContents(PROJECT_ID, downloadFullBucketName, tmp.getRoot().toPath()); + String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String(); + assertThat(snippetOutput.contains("blob1")).isTrue(); + assertThat(snippetOutput.contains("blob2")).isTrue(); + assertThat(snippetOutput.contains("blob3")).isTrue(); + } + @Test public void downloadFiles() { DownloadMany.downloadManyBlobs(BUCKET, blobs, tmp.getRoot().toPath());