Skip to content

Commit a35f8c0

Browse files
committed
Make UnifiedHostTest.testWorkspaceIdFromEnvironmentVariables hermetic with FixtureServer
Replace real mycompany.databricks.com hostname with FixtureServer to prevent host metadata resolution from hitting live servers during tests. Co-authored-by: Isaac
1 parent e81a221 commit a35f8c0

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import com.databricks.sdk.core.utils.Environment;
6+
import java.io.IOException;
67
import java.util.*;
78
import java.util.stream.Stream;
89
import org.junit.jupiter.api.Test;
@@ -96,18 +97,20 @@ public void testIsAccountClientForNonAccountsHost() {
9697
// --- Environment Variable Tests ---
9798

9899
@Test
99-
public void testWorkspaceIdFromEnvironmentVariables() {
100-
Map<String, String> env = new HashMap<>();
101-
env.put("DATABRICKS_HOST", "https://mycompany.databricks.com");
102-
env.put("DATABRICKS_WORKSPACE_ID", "987654321");
103-
env.put("DATABRICKS_ACCOUNT_ID", "account-abc");
104-
105-
DatabricksConfig config = new DatabricksConfig();
106-
config.resolve(new Environment(env, new ArrayList<>(), System.getProperty("os.name")));
107-
108-
assertEquals(HostType.WORKSPACE, config.getHostType());
109-
assertEquals("987654321", config.getWorkspaceId());
110-
assertEquals("account-abc", config.getAccountId());
111-
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+
}
112115
}
113116
}

0 commit comments

Comments
 (0)