Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update StorageOptions to not overwrite any previously set host #1142

Merged
merged 1 commit into from Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
}
}