|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.storage.it; |
| 18 | + |
| 19 | +import static org.junit.Assume.assumeTrue; |
| 20 | + |
| 21 | +import com.google.auth.Credentials; |
| 22 | +import com.google.auth.oauth2.GoogleCredentials; |
| 23 | +import com.google.auth.oauth2.OAuth2Credentials; |
| 24 | +import com.google.cloud.NoCredentials; |
| 25 | +import com.google.cloud.storage.Storage; |
| 26 | +import com.google.cloud.storage.StorageOptions; |
| 27 | +import com.google.cloud.storage.TestUtils; |
| 28 | +import com.google.cloud.storage.it.ITStorageOptionsTest.CredentialsParameters; |
| 29 | +import com.google.cloud.storage.it.runner.StorageITRunner; |
| 30 | +import com.google.cloud.storage.it.runner.annotations.Backend; |
| 31 | +import com.google.cloud.storage.it.runner.annotations.Parameterized; |
| 32 | +import com.google.cloud.storage.it.runner.annotations.Parameterized.Parameter; |
| 33 | +import com.google.cloud.storage.it.runner.annotations.Parameterized.ParametersProvider; |
| 34 | +import com.google.cloud.storage.it.runner.annotations.SingleBackend; |
| 35 | +import com.google.common.collect.ImmutableList; |
| 36 | +import org.junit.Ignore; |
| 37 | +import org.junit.Test; |
| 38 | +import org.junit.runner.RunWith; |
| 39 | + |
| 40 | +@RunWith(StorageITRunner.class) |
| 41 | +@SingleBackend(Backend.PROD) |
| 42 | +@Parameterized(CredentialsParameters.class) |
| 43 | +public final class ITStorageOptionsTest { |
| 44 | + |
| 45 | + public static final class CredentialsParameters implements ParametersProvider { |
| 46 | + |
| 47 | + @Override |
| 48 | + public ImmutableList<?> parameters() { |
| 49 | + return ImmutableList.of( |
| 50 | + NoCredentials.getInstance(), |
| 51 | + GoogleCredentials.create(/* accessToken= */ null), |
| 52 | + OAuth2Credentials.create(null)); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Parameter public Credentials credentials; |
| 57 | + |
| 58 | + @Test |
| 59 | + public void clientShouldConstructCleanly_http() throws Exception { |
| 60 | + StorageOptions options = StorageOptions.http().setCredentials(credentials).build(); |
| 61 | + doTest(options); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void clientShouldConstructCleanly_grpc() throws Exception { |
| 66 | + StorageOptions options = |
| 67 | + StorageOptions.grpc().setCredentials(credentials).setAttemptDirectPath(false).build(); |
| 68 | + doTest(options); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + @Ignore("waiting on conformation from the backend team if this should even be possible") |
| 73 | + public void clientShouldConstructCleanly_directPath() throws Exception { |
| 74 | + assumeTrue( |
| 75 | + "Unable to determine environment can access directPath", TestUtils.isOnComputeEngine()); |
| 76 | + StorageOptions options = |
| 77 | + StorageOptions.grpc().setCredentials(credentials).setAttemptDirectPath(true).build(); |
| 78 | + doTest(options); |
| 79 | + } |
| 80 | + |
| 81 | + private static void doTest(StorageOptions options) throws Exception { |
| 82 | + //noinspection EmptyTryBlock |
| 83 | + try (Storage ignore = options.getService()) {} |
| 84 | + } |
| 85 | +} |
0 commit comments