Skip to content

Commit

Permalink
reusing variables
Browse files Browse the repository at this point in the history
Signed-off-by: fahadshamiinsta <fshami@netapp.com>
  • Loading branch information
fahadshamiinsta committed Dec 4, 2023
1 parent cf02c66 commit b679a72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.repositories.gcs;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.storage.StorageOptions;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@

public class GoogleCloudStorageServiceTests extends OpenSearchTestCase {

final TimeValue connectTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final TimeValue readTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final String applicationName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
final String endpoint = randomFrom("http://", "https://")
+ randomFrom("www.opensearch.org", "www.googleapis.com", "localhost/api", "google.com/oauth")
+ ":"
+ randomIntBetween(1, 65535);
final String projectIdName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);

public void testClientInitializer() throws Exception {
final String clientName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
final TimeValue connectTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final TimeValue readTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final String applicationName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
final String endpoint = randomFrom("http://", "https://")
+ randomFrom("www.opensearch.org", "www.googleapis.com", "localhost/api", "google.com/oauth")
+ ":"
+ randomIntBetween(1, 65535);
final String projectIdName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
final Settings settings = Settings.builder()
.put(
GoogleCloudStorageClientSettings.CONNECT_TIMEOUT_SETTING.getConcreteSettingForNamespace(clientName).getKey(),
Expand Down Expand Up @@ -205,8 +206,8 @@ public void testToTimeout() {
assertEquals(0, GoogleCloudStorageService.toTimeout(TimeValue.MINUS_ONE).intValue());
}
/*
The following methods test the Google Application Default Credential instead of
service account file.
The following method test the Google Application Default Credential instead of
using service account file.
Considered use of Junit Mocking due to static method GoogleCredentials.getApplicationDefault
and avoiding environment variables to set which later use GCE.
*/
Expand All @@ -221,7 +222,6 @@ public void testApplicationDefaultCredential() throws Exception {
StorageOptions storageOptions = service.createStorageOptions(settings,mockHttpTransportOptions);
assertNotNull(storageOptions);
assertEquals(storageOptions.getCredentials().toString(),mockGoogleCredentials.toString());

}

/**
Expand All @@ -243,16 +243,7 @@ public void applicationDefaultCredentialThrowsErrorWhenNotAvailable() throws Exc
assertThat(exception.getMessage(),containsString("The Application Default Credentials are not available"));

}
private static GoogleCloudStorageClientSettings getGoogleCloudStorageClientSettings() throws URISyntaxException {
final TimeValue connectTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final TimeValue readTimeValue = TimeValue.timeValueNanos(randomIntBetween(0, 2000000));
final String applicationName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
final String endpoint = randomFrom("http://", "https://")
+ randomFrom("www.opensearch.org", "www.googleapis.com", "localhost/api", "google.com/oauth")
+ ":"
+ randomIntBetween(1, 65535);
final String projectIdName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);

private GoogleCloudStorageClientSettings getGoogleCloudStorageClientSettings() throws URISyntaxException {
return new GoogleCloudStorageClientSettings(
null,endpoint,projectIdName,
connectTimeValue,readTimeValue,applicationName,
Expand Down

0 comments on commit b679a72

Please sign in to comment.