Skip to content

Commit 1986cf8

Browse files
committed
Fix fixture double-consumption and experimental flag in tests
- Add second fixture registration for tests that call both resolve() and resolveHostMetadata(), since resolve() internally calls tryResolveHostMetadata() consuming the first fixture. - Replace setExperimentalIsUnifiedHost(true) with host_type in metadata response, since PR #720 removed the experimental flag check from getHostType().
1 parent fb872e2 commit 1986cf8

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,9 @@ public void testResolveHostMetadataPopulatesResolvedHostType() throws IOExceptio
668668
+ "\","
669669
+ "\"host_type\":\"workspace\"}";
670670
try (FixtureServer server =
671-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
671+
new FixtureServer()
672+
.with("GET", "/.well-known/databricks-config", response, 200)
673+
.with("GET", "/.well-known/databricks-config", response, 200)) {
672674
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
673675
config.resolve(emptyEnv());
674676
config.resolveHostMetadata();
@@ -685,7 +687,9 @@ public void testResolveHostMetadataDoesNotOverwriteExistingHostType() throws IOE
685687
+ "\","
686688
+ "\"host_type\":\"workspace\"}";
687689
try (FixtureServer server =
688-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
690+
new FixtureServer()
691+
.with("GET", "/.well-known/databricks-config", response, 200)
692+
.with("GET", "/.well-known/databricks-config", response, 200)) {
689693
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
690694
config.resolve(emptyEnv());
691695
config.setResolvedHostType(HostType.UNIFIED);
@@ -703,7 +707,9 @@ public void testResolveHostMetadataUnknownHostTypeIgnored() throws IOException {
703707
+ "\","
704708
+ "\"host_type\":\"unknown_value\"}";
705709
try (FixtureServer server =
706-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
710+
new FixtureServer()
711+
.with("GET", "/.well-known/databricks-config", response, 200)
712+
.with("GET", "/.well-known/databricks-config", response, 200)) {
707713
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
708714
config.resolve(emptyEnv());
709715
config.resolveHostMetadata();
@@ -720,7 +726,9 @@ public void testResolveHostMetadataHostTypeAccount() throws IOException {
720726
+ "\","
721727
+ "\"host_type\":\"account\"}";
722728
try (FixtureServer server =
723-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
729+
new FixtureServer()
730+
.with("GET", "/.well-known/databricks-config", response, 200)
731+
.with("GET", "/.well-known/databricks-config", response, 200)) {
724732
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
725733
config.resolve(emptyEnv());
726734
config.resolveHostMetadata();
@@ -737,7 +745,9 @@ public void testResolveHostMetadataHostTypeUnified() throws IOException {
737745
+ "\","
738746
+ "\"host_type\":\"unified\"}";
739747
try (FixtureServer server =
740-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
748+
new FixtureServer()
749+
.with("GET", "/.well-known/databricks-config", response, 200)
750+
.with("GET", "/.well-known/databricks-config", response, 200)) {
741751
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
742752
config.resolve(emptyEnv());
743753
config.resolveHostMetadata();
@@ -756,7 +766,9 @@ public void testResolveHostMetadataSetsTokenAudienceFromDefaultOidcAudience() th
756766
+ "\","
757767
+ "\"default_oidc_audience\":\"https://ws.databricks.com/oidc/v1/token\"}";
758768
try (FixtureServer server =
759-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
769+
new FixtureServer()
770+
.with("GET", "/.well-known/databricks-config", response, 200)
771+
.with("GET", "/.well-known/databricks-config", response, 200)) {
760772
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
761773
config.resolve(emptyEnv());
762774
config.resolveHostMetadata();
@@ -773,18 +785,14 @@ public void testResolveHostMetadataDefaultOidcAudiencePriorityOverAccountIdFallb
773785
+ "\"account_id\":\""
774786
+ DUMMY_ACCOUNT_ID
775787
+ "\","
788+
+ "\"host_type\":\"account\","
776789
+ "\"default_oidc_audience\":\"custom-audience\"}";
777790
try (FixtureServer server =
778-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
791+
new FixtureServer()
792+
.with("GET", "/.well-known/databricks-config", response, 200)
793+
.with("GET", "/.well-known/databricks-config", response, 200)) {
779794
DatabricksConfig config =
780-
new DatabricksConfig()
781-
.setHost(server.getUrl())
782-
.setExperimentalIsUnifiedHost(true)
783-
.setAccountId(DUMMY_ACCOUNT_ID);
784-
// Note: need two fixtures — resolve() consumes first one (unified host triggers
785-
// tryResolveHostMetadata)
786-
// Instead, don't set unified — just test direct call
787-
config = new DatabricksConfig().setHost(server.getUrl()).setAccountId(DUMMY_ACCOUNT_ID);
795+
new DatabricksConfig().setHost(server.getUrl()).setAccountId(DUMMY_ACCOUNT_ID);
788796
config.resolve(emptyEnv());
789797
config.resolveHostMetadata();
790798
// Should use default_oidc_audience, NOT account_id
@@ -802,7 +810,9 @@ public void testResolveHostMetadataDoesNotOverrideExistingTokenAudienceWithOidcA
802810
+ "\","
803811
+ "\"default_oidc_audience\":\"metadata-audience\"}";
804812
try (FixtureServer server =
805-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
813+
new FixtureServer()
814+
.with("GET", "/.well-known/databricks-config", response, 200)
815+
.with("GET", "/.well-known/databricks-config", response, 200)) {
806816
DatabricksConfig config =
807817
new DatabricksConfig().setHost(server.getUrl()).setTokenAudience("existing-audience");
808818
config.resolve(emptyEnv());
@@ -815,24 +825,23 @@ public void testResolveHostMetadataDoesNotOverrideExistingTokenAudienceWithOidcA
815825
public void testResolveHostMetadataFallsBackToAccountIdWhenNoDefaultOidcAudience()
816826
throws IOException {
817827
// When no default_oidc_audience, should fall back to account_id for account hosts.
818-
// Use unified host flag so getClientType() returns ACCOUNT (no workspaceId).
828+
// Use host_type=account in metadata so getClientType() returns ACCOUNT.
819829
String response =
820830
"{\"oidc_endpoint\":\"https://acc.databricks.com/oidc/accounts/{account_id}\","
821831
+ "\"account_id\":\""
822832
+ DUMMY_ACCOUNT_ID
823-
+ "\"}";
833+
+ "\","
834+
+ "\"host_type\":\"account\"}";
824835
try (FixtureServer server =
825836
new FixtureServer()
826-
.with("GET", "/.well-known/databricks-config", response, 200)
827837
.with("GET", "/.well-known/databricks-config", response, 200)) {
828838
DatabricksConfig config =
829839
new DatabricksConfig()
830840
.setHost(server.getUrl())
831-
.setAccountId(DUMMY_ACCOUNT_ID)
832-
.setExperimentalIsUnifiedHost(true);
841+
.setAccountId(DUMMY_ACCOUNT_ID);
833842
config.resolve(emptyEnv());
834-
// resolve() with unified flag triggers tryResolveHostMetadata() consuming first fixture.
835-
// Now call again with second fixture to verify account_id fallback.
843+
// resolve() triggers tryResolveHostMetadata() which sets resolvedHostType=ACCOUNTS,
844+
// then the tokenAudience fallback sets tokenAudience to accountId.
836845
assertEquals(DUMMY_ACCOUNT_ID, config.getTokenAudience());
837846
}
838847
}

0 commit comments

Comments
 (0)