-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathDatabricksCliCheck.test.ts
More file actions
81 lines (71 loc) · 2.81 KB
/
Copy pathDatabricksCliCheck.test.ts
File metadata and controls
81 lines (71 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import * as assert from "assert";
import {instance, mock, when} from "ts-mockito";
import {DatabricksCliCheck, LOGIN_TIMEOUT_SECONDS} from "./DatabricksCliCheck";
import {DatabricksCliAuthProvider} from "./AuthProvider";
describe(__filename, () => {
const cliPath = "/path/to/bin/databricks";
function createProvider(profile?: string) {
const provider = mock(DatabricksCliAuthProvider);
when(provider.host).thenReturn(
new URL("https://test.cloud.databricks.com")
);
when(provider.cliPath).thenReturn(cliPath);
when(provider.profile).thenReturn(profile);
return instance(provider);
}
describe("login", () => {
it("passes a bounded --timeout to auth login so it cannot hang indefinitely", async () => {
let capturedArgs: string[] | undefined;
const check = new DatabricksCliCheck(
createProvider("dev"),
async (_file, args) => {
capturedArgs = args;
return {stdout: "", stderr: ""};
}
);
await (check as any).login();
assert.ok(capturedArgs, "execFile should have been invoked");
assert.deepStrictEqual(capturedArgs, [
"auth",
"login",
"--profile",
"dev",
"--timeout",
`${LOGIN_TIMEOUT_SECONDS}s`,
]);
});
it("uses --host when no profile is configured", async () => {
let capturedArgs: string[] | undefined;
const check = new DatabricksCliCheck(
createProvider(undefined),
async (_file, args) => {
capturedArgs = args;
return {stdout: "", stderr: ""};
}
);
await (check as any).login();
assert.deepStrictEqual(capturedArgs, [
"auth",
"login",
"--host",
"https://test.cloud.databricks.com",
"--timeout",
`${LOGIN_TIMEOUT_SECONDS}s`,
]);
});
it("surfaces an actionable message when login fails (e.g. WSL browser hang/timeout)", async () => {
const check = new DatabricksCliCheck(
createProvider("dev"),
async () => {
throw {stderr: "context deadline exceeded"};
}
);
await assert.rejects((check as any).login(), (e: Error) => {
assert.match(e.message, /context deadline exceeded/);
// Tells the user how to recover instead of leaving them stuck.
assert.match(e.message, /databricks auth login --profile dev/);
return true;
});
});
});
});