Skip to content

Commit 91389f1

Browse files
committed
Make tests hermetic by using FixtureServer instead of real hostnames
- testWorkspaceIdFromEnvironmentVariables: use FixtureServer URL instead of https://mycompany.databricks.com to avoid hitting real /.well-known/databricks-config during resolve(). - testNewWithWorkspaceHost: use FixtureServer URL as workspace host instead of https://workspace.cloud.databricks.com. - Remove unnecessary second fixture from testEndToEndResolveToGetHostType.
1 parent 6dfbf98 commit 91389f1

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,24 @@ public void testDiscoveryEndpoint() throws IOException {
173173
}
174174

175175
@Test
176-
public void testNewWithWorkspaceHost() {
177-
DatabricksConfig config =
178-
new DatabricksConfig()
179-
.setAuthType("oauth-m2m")
180-
.setClientId("my-client-id")
181-
.setClientSecret("my-client-secret")
182-
.setAccountId("account-id")
183-
.setHost("https://account.cloud.databricks.com");
184-
String workspaceHost = "https://workspace.cloud.databricks.com";
185-
186-
DatabricksConfig newWorkspaceConfig = config.newWithWorkspaceHost(workspaceHost).resolve();
187-
188-
assert newWorkspaceConfig.getHost().equals(workspaceHost);
189-
assert newWorkspaceConfig.getAuthType().equals("oauth-m2m");
190-
assert newWorkspaceConfig.getClientId().equals("my-client-id");
191-
assert newWorkspaceConfig.getClientSecret().equals("my-client-secret");
176+
public void testNewWithWorkspaceHost() throws IOException {
177+
try (FixtureServer server = new FixtureServer()) {
178+
String workspaceHost = server.getUrl();
179+
DatabricksConfig config =
180+
new DatabricksConfig()
181+
.setAuthType("oauth-m2m")
182+
.setClientId("my-client-id")
183+
.setClientSecret("my-client-secret")
184+
.setAccountId("account-id")
185+
.setHost("https://account.cloud.databricks.com");
186+
187+
DatabricksConfig newWorkspaceConfig = config.newWithWorkspaceHost(workspaceHost).resolve();
188+
189+
assert newWorkspaceConfig.getHost().equals(workspaceHost);
190+
assert newWorkspaceConfig.getAuthType().equals("oauth-m2m");
191+
assert newWorkspaceConfig.getClientId().equals("my-client-id");
192+
assert newWorkspaceConfig.getClientSecret().equals("my-client-secret");
193+
}
192194
}
193195

194196
@Test

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,21 @@ public void testIsAccountClientForNonAccountsHost() {
9797
// --- Environment Variable Tests ---
9898

9999
@Test
100-
public void testWorkspaceIdFromEnvironmentVariables() {
101-
Map<String, String> env = new HashMap<>();
102-
env.put("DATABRICKS_HOST", "https://mycompany.databricks.com");
103-
env.put("DATABRICKS_WORKSPACE_ID", "987654321");
104-
env.put("DATABRICKS_ACCOUNT_ID", "account-abc");
105-
106-
DatabricksConfig config = new DatabricksConfig();
107-
config.resolve(new Environment(env, new ArrayList<>(), System.getProperty("os.name")));
108-
109-
assertEquals(HostType.WORKSPACE, config.getHostType());
110-
assertEquals("987654321", config.getWorkspaceId());
111-
assertEquals("account-abc", config.getAccountId());
112-
assertEquals(ClientType.WORKSPACE, config.getClientType());
100+
public void testWorkspaceIdFromEnvironmentVariables() throws IOException {
101+
try (FixtureServer server = new FixtureServer()) {
102+
Map<String, String> env = new HashMap<>();
103+
env.put("DATABRICKS_HOST", server.getUrl());
104+
env.put("DATABRICKS_WORKSPACE_ID", "987654321");
105+
env.put("DATABRICKS_ACCOUNT_ID", "account-abc");
106+
107+
DatabricksConfig config = new DatabricksConfig();
108+
config.resolve(new Environment(env, new ArrayList<>(), System.getProperty("os.name")));
109+
110+
assertEquals(HostType.WORKSPACE, config.getHostType());
111+
assertEquals("987654321", config.getWorkspaceId());
112+
assertEquals("account-abc", config.getAccountId());
113+
assertEquals(ClientType.WORKSPACE, config.getClientType());
114+
}
113115
}
114116

115117
// --- Resolved host type from metadata tests ---
@@ -167,7 +169,6 @@ public void testEndToEndResolveToGetHostType() throws IOException {
167169
+ "\"host_type\":\"unified\"}";
168170
try (FixtureServer server =
169171
new FixtureServer()
170-
.with("GET", "/.well-known/databricks-config", response, 200)
171172
.with("GET", "/.well-known/databricks-config", response, 200)) {
172173
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
173174
config.resolve(

0 commit comments

Comments
 (0)