Skip to content

Commit

Permalink
Add test to verify file is actually downloaded with FakeStorageRpc (#…
Browse files Browse the repository at this point in the history
…7038)

* Add test to verify file is actually downloaded with FakeStorageRpc

* Add test to verify file is actually downloaded with FakeStorageRpc
  • Loading branch information
JesseLovelace committed Dec 13, 2019
1 parent 848bf90 commit db554de
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -23,9 +23,12 @@
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -74,11 +77,15 @@ private Storage.CopyRequest copyRequest() {
}

@Test
public void testCopyCanBeRead() {
public void testCopyCanBeRead() throws Exception {
Storage.CopyRequest request = copyRequest();
localStorageService.copy(request).getResult();
Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile));
String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch()));
File file = File.createTempFile("file", ".txt");
file.deleteOnExit();
obj.downloadTo(file.toPath());
Assert.assertArrayEquals(payload.getBytes(), Files.readAllBytes(file.toPath()));

assertThat(copiedContents).isEqualTo(payload);
assertThat(obj.getGeneration()).isEqualTo(1);
Expand Down

0 comments on commit db554de

Please sign in to comment.