Skip to content

Commit e5f0fba

Browse files
Add assumptions to storage integration tests (#3813)
1 parent 89d6abe commit e5f0fba

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

  • google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it

google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
import static org.junit.Assert.assertNull;
2626
import static org.junit.Assert.assertTrue;
2727
import static org.junit.Assert.fail;
28+
import static org.junit.Assume.assumeFalse;
29+
import static org.junit.Assume.assumeTrue;
2830

31+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
2932
import com.google.api.gax.paging.Page;
33+
import com.google.auth.ServiceAccountSigner;
3034
import com.google.auth.oauth2.GoogleCredentials;
3135
import com.google.cloud.kms.v1.CreateCryptoKeyRequest;
3236
import com.google.cloud.kms.v1.CreateKeyRingRequest;
@@ -1604,6 +1608,10 @@ public void testWriteChannelExistingBlob() throws IOException {
16041608

16051609
@Test
16061610
public void testGetSignedUrl() throws IOException {
1611+
if(storage.getOptions().getCredentials() != null) {
1612+
assumeTrue(storage.getOptions().getCredentials() instanceof ServiceAccountSigner);
1613+
}
1614+
16071615
String blobName = "test-get-signed-url-blob/with/slashes/and?special=!#$&'()*+,:;=?@[]";
16081616
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
16091617
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
@@ -1619,6 +1627,9 @@ public void testGetSignedUrl() throws IOException {
16191627

16201628
@Test
16211629
public void testPostSignedUrl() throws IOException {
1630+
if (storage.getOptions().getCredentials() != null) {
1631+
assumeTrue(storage.getOptions().getCredentials() instanceof ServiceAccountSigner);
1632+
}
16221633
String blobName = "test-post-signed-url-blob";
16231634
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
16241635
assertNotNull(storage.create(blob));
@@ -1657,7 +1668,13 @@ public void testDownloadPublicBlobWithoutAuthentication() {
16571668
String landsatBucket = "gcp-public-data-landsat";
16581669
String landsatPrefix = "LC08/PRE/044/034/LC80440342016259LGN00/";
16591670
String landsatBlob = landsatPrefix + "LC80440342016259LGN00_MTL.txt";
1660-
byte[] bytes = unauthorizedStorage.readAllBytes(landsatBucket, landsatBlob);
1671+
byte[] bytes;
1672+
try {
1673+
bytes = unauthorizedStorage.readAllBytes(landsatBucket, landsatBlob);
1674+
} catch (StorageException ex) {
1675+
assumeFalse(403 == ex.getCode());
1676+
return;
1677+
}
16611678
assertThat(bytes.length).isEqualTo(7903);
16621679
int numBlobs = 0;
16631680
Iterator<Blob> blobIterator = unauthorizedStorage

0 commit comments

Comments
 (0)