Skip to content

Commit d05f55a

Browse files
committed
Add unit tests for X-Databricks-Workspace-Id header gating in AppsImpl
* `testWorkspaceIdHeaderSentWhenConfigured` — when ApiClient#workspaceId() returns a value, a workspace-scoped impl forwards it on the X-Databricks-Workspace-Id request header. * `testWorkspaceIdHeaderOmittedWhenUnset` — when ApiClient#workspaceId() returns null, the header is not sent (so calls to legacy single-workspace hosts don't pick up an empty value). AppsImpl is one representative of the generator-emitted workspace-scoped shape; if the generator template regresses on either branch (drops the header, misspells it, or skips the null guard) the next regen would reshape AppsImpl and at least one assertion would fail. Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
1 parent 3dfcc08 commit d05f55a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

databricks-sdk-java/src/test/java/com/databricks/sdk/service/apps/AppsImplTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,42 @@ public void testCreateAppIncludesNoComputeParameter() throws IOException {
4141
}),
4242
eq(App.class));
4343
}
44+
45+
// On unified ("SPOG") hosts, workspace-scoped requests must carry an
46+
// X-Databricks-Workspace-Id header so the gateway can route them to the
47+
// correct workspace. When ApiClient#workspaceId() returns a value, every
48+
// generated *Impl must forward it on the request; when it returns null,
49+
// the header must be omitted (so calls to legacy single-workspace hosts
50+
// don't pick up an empty value).
51+
@Test
52+
public void testWorkspaceIdHeaderSentWhenConfigured() throws IOException {
53+
ApiClient apiClient = Mockito.mock(ApiClient.class);
54+
when(apiClient.workspaceId()).thenReturn("7474644166319138");
55+
when(apiClient.execute(any(), any())).thenReturn(null);
56+
57+
AppsService apps = new AppsImpl(apiClient);
58+
apps.list(new ListAppsRequest());
59+
60+
verify(apiClient)
61+
.execute(
62+
argThat(
63+
(Request req) ->
64+
"7474644166319138".equals(req.getHeaders().get("X-Databricks-Workspace-Id"))),
65+
any());
66+
}
67+
68+
@Test
69+
public void testWorkspaceIdHeaderOmittedWhenUnset() throws IOException {
70+
ApiClient apiClient = Mockito.mock(ApiClient.class);
71+
when(apiClient.workspaceId()).thenReturn(null);
72+
when(apiClient.execute(any(), any())).thenReturn(null);
73+
74+
AppsService apps = new AppsImpl(apiClient);
75+
apps.list(new ListAppsRequest());
76+
77+
verify(apiClient)
78+
.execute(
79+
argThat((Request req) -> !req.getHeaders().containsKey("X-Databricks-Workspace-Id")),
80+
any());
81+
}
4482
}

0 commit comments

Comments
 (0)