Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: update StorageOptions to not overwrite any previously set host (#…
…1142)

When calling `StorageOptions#toBuilder()` after creating the builder the host was explicitly set to the default host. This change removes that behavior instead moving the setting of the default host to the instantiation of a new builder.

Add unit tests to ensure host is set to the expected values based on different ways of creating an instance of StorageOptions.

Related:
* googleapis/google-cloud-java#6579
* googleapis/google-cloud-java#7004
* googleapis/google-cloud-java#7034
  • Loading branch information
BenWhitehead committed Nov 18, 2021
1 parent fe6d12f commit 05375c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -166,7 +166,7 @@ public static StorageOptions getUnauthenticatedInstance() {
@SuppressWarnings("unchecked")
@Override
public Builder toBuilder() {
return new Builder(this).setHost(DEFAULT_HOST);
return new Builder(this);
}

@Override
Expand Down
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.storage;

import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.TransportOptions;
import org.easymock.EasyMock;
import org.junit.Assert;
Expand All @@ -33,4 +35,34 @@ public void testInvalidTransport() {
Assert.assertNotNull(ex.getMessage());
}
}

@Test
public void testConfigureHostShouldBeKeptOnToBuilder() {
StorageOptions opts1 = StorageOptions.newBuilder().setHost("custom-host").build();
StorageOptions opts2 = opts1.toBuilder().build();

assertThat(opts2.getHost()).isEqualTo("custom-host");
}

@Test
public void testToBuilderShouldSpecifyDefaultIfNotOtherwiseSet() {
StorageOptions opts1 = StorageOptions.newBuilder().build();
StorageOptions opts2 = opts1.toBuilder().build();

assertThat(opts2.getHost()).isEqualTo("https://storage.googleapis.com");
}

@Test
public void testNewBuilderSpecifiesCorrectHost() {
StorageOptions opts1 = StorageOptions.newBuilder().build();

assertThat(opts1.getHost()).isEqualTo("https://storage.googleapis.com");
}

@Test
public void testDefaultInstanceSpecifiesCorrectHost() {
StorageOptions opts1 = StorageOptions.getDefaultInstance();

assertThat(opts1.getHost()).isEqualTo("https://storage.googleapis.com");
}
}

0 comments on commit 05375c0

Please sign in to comment.