-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from snazy/default-project-id-no-google-http
Do not use Google's HTTP client to get the default project ID
- Loading branch information
Showing
4 changed files
with
225 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...st/java/io/quarkiverse/googlecloudservices/common/GcpDefaultsConfigSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkiverse.googlecloudservices.common; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.smallrye.config.ConfigSourceContext; | ||
import io.smallrye.config.ConfigValue; | ||
|
||
class GcpDefaultsConfigSourceFactoryTest { | ||
@Test | ||
void configSourceWorks() { | ||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("true").build()); | ||
|
||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory(() -> "test-project-id") | ||
.getConfigSources(context); | ||
assertThat(configSources).asList().hasSize(1); | ||
|
||
ConfigSource configSource = configSources.iterator().next(); | ||
assertThat(configSource.getProperties()).containsEntry("quarkus.google.cloud.project-id", "test-project-id"); | ||
} | ||
|
||
@Test | ||
void metadataServerDisabled() { | ||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("false").build()); | ||
|
||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory(() -> "test-project-id") | ||
.getConfigSources(context); | ||
assertThat(configSources).isEmpty(); | ||
} | ||
|
||
/** | ||
* Tests that OpenCensus does not get implicitly initialized and in turn does not "collide" with | ||
* OpenTelemetry, as used in Quarkus. | ||
*/ | ||
@Test | ||
void staticOpenCensusOpenTelemetryInit() { | ||
try { | ||
GlobalOpenTelemetry.resetForTest(); | ||
|
||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("true").build()); | ||
|
||
// Uses the "real" implementation that tries to fetch the default-project-id | ||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory().getConfigSources(context); | ||
assertThat(configSources).asList().hasSizeLessThanOrEqualTo(1); | ||
|
||
// This is a pretty ugly way, because it changes static state | ||
GlobalOpenTelemetry.set(OpenTelemetry.noop()); | ||
} finally { | ||
GlobalOpenTelemetry.resetForTest(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
<compiler-plugin.version>3.8.1</compiler-plugin.version> | ||
<enforcer-plugin.version>3.4.1</enforcer-plugin.version> | ||
<assertj.version>3.24.2</assertj.version> | ||
<opentelemetry-alpha.version>1.28.0-alpha</opentelemetry-alpha.version> | ||
</properties> | ||
<scm> | ||
<connection>scm:git:[email protected]:quarkiverse/quarkus-google-cloud-services.git</connection> | ||
|
@@ -63,6 +64,11 @@ | |
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-opencensus-shim</artifactId> | ||
<version>${opentelemetry-alpha.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
|