Skip to content

Commit af48fce

Browse files
[GH-15] Use terraformed cluster for tests (#37)
* rename environment variables to match those generated by terraform
1 parent 13b3186 commit af48fce

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
env:
6666
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
6767
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
68-
DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }}
68+
TEST_DEFAULT_CLUSTER_ID: ${{ secrets.TEST_DEFAULT_CLUSTER_ID }}
6969

7070
test-extension:
7171
name: Test VSCode Extension
@@ -82,7 +82,7 @@ jobs:
8282
VSCODE_TEST_VERSION: ${{ matrix.vscode-version }}
8383
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
8484
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
85-
DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }}
85+
TEST_DEFAULT_CLUSTER_ID: ${{ secrets.TEST_DEFAULT_CLUSTER_ID }}
8686

8787
steps:
8888
- uses: actions/checkout@v3

packages/databricks-sdk-js/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ npm run test
2121

2222
Most of the tests are integrations tests and must be run against a life cluster. To run the integration tests you need to configure the following environment variables:
2323

24-
| Name | Value |
25-
| --------------------- | --------------------------------------------------------------------------------------------------------- |
26-
| DATABRICKS_HOST | Hostname of the Databricks workspace (starts with https://) |
27-
| DATABRICKS_TOKEN | Personal access token |
28-
| DATABRICKS_CLUSTER_ID | (optional) ID of a cluster to run the tests agains. If missing the tests will create a cluster on demand. |
24+
| Name | Value |
25+
| ----------------------- | --------------------------------------------------------------------------------------------------------- |
26+
| DATABRICKS_HOST | Hostname of the Databricks workspace (starts with https://) |
27+
| DATABRICKS_TOKEN | Personal access token |
28+
| TEST_DEFAULT_CLUSTER_ID | (optional) ID of a cluster to run the tests agains. If missing the tests will create a cluster on demand. |

packages/databricks-sdk-js/src/apis/executionContext.integ.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe(__filename, function () {
5555
assert.equal(status.results.data, "juhu");
5656

5757
await executionContextApi.destroy({
58-
clusterId: "1118-013127-82wynr8t",
58+
clusterId: integSetup.clusterId,
5959
contextId: context.id,
6060
});
6161
});

packages/databricks-sdk-js/src/auth/fromEnv.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import {CredentialProvider, CredentialsProviderError} from "./types";
22

3+
function getValidHost(host: string) {
4+
return !/https:\/\/.+/.test(host) && !/http:\/\/.+/.test(host)
5+
? `https://${host}`
6+
: host;
7+
}
8+
9+
function strip(strToStrip: string, str: string) {
10+
return str.split(strToStrip).join("");
11+
}
12+
313
export const fromEnv = (): CredentialProvider => {
414
return async () => {
515
const host = process.env["DATABRICKS_HOST"];
616
const token = process.env["DATABRICKS_TOKEN"];
717

818
if (host && token) {
919
return {
10-
token: token,
11-
host: new URL(host),
20+
token: strip("'", token),
21+
host: new URL(getValidHost(strip("'", host))),
1222
};
1323
}
1424

packages/databricks-sdk-js/src/test/IntegrationTestSetup.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import {v4 as uuidv4} from "uuid";
44
import {ApiClient} from "../api-client";
55
import {ClusterService} from "../apis/cluster";
6-
import {fromEnv} from "../auth/fromEnv";
76

87
export class IntegrationTestSetup {
98
readonly testRunId: string;
@@ -15,17 +14,17 @@ export class IntegrationTestSetup {
1514
private static _instance: IntegrationTestSetup;
1615
static async getInstance(): Promise<IntegrationTestSetup> {
1716
if (!this._instance) {
18-
let clusterId;
1917
let client = new ApiClient();
2018
let clustersApi = new ClusterService(client);
2119

22-
if (!process.env["DATABRICKS_CLUSTER_ID"]) {
20+
if (!process.env["TEST_DEFAULT_CLUSTER_ID"]) {
2321
throw new Error(
24-
"Environment variable 'DATABRICKS_CLUSTER_ID' must be set"
22+
"Environment variable 'TEST_DEFAULT_CLUSTER_ID' must be set"
2523
);
2624
}
2725

28-
clusterId = process.env["DATABRICKS_CLUSTER_ID"];
26+
const clusterId =
27+
process.env["TEST_DEFAULT_CLUSTER_ID"]!.split("'").join("");
2928
clustersApi.start({cluster_id: clusterId});
3029

3130
// wait for cluster to be running

packages/databricks-vscode/src/test/e2e/run_on_cluster.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("Run python on cluster", function () {
3030
await fs.writeFile(
3131
path.join(projectDir, ".databricks", "project.json"),
3232
JSON.stringify({
33-
clusterId: process.env["DATABRICKS_CLUSTER_ID"],
33+
clusterId: process.env["TEST_DEFAULT_CLUSTER_ID"],
3434
profile: "DEFAULT",
3535
})
3636
);

packages/databricks-vscode/src/test/e2e/scripts/e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ async function main(args: string[]) {
1717
"Environment variable DATABRICKS_TOKEN must be set"
1818
);
1919
assert(
20-
process.env["DATABRICKS_CLUSTER_ID"],
21-
"Environment variable DATABRICKS_CLUSTER_ID must be set"
20+
process.env["TEST_DEFAULT_CLUSTER_ID"],
21+
"Environment variable TEST_DEFAULT_CLUSTER_ID must be set"
2222
);
2323

2424
const {path: configFile, cleanup} = await tmp.file();
@@ -32,7 +32,7 @@ token = ${process.env["DATABRICKS_TOKEN"]}`
3232

3333
const child = spawn("extest", ["run-tests", ...args], {
3434
env: {
35-
DATABRICKS_CLUSTER_ID: process.env["DATABRICKS_CLUSTER_ID"],
35+
TEST_DEFAULT_CLUSTER_ID: process.env["TEST_DEFAULT_CLUSTER_ID"],
3636
DATABRICKS_CONFIG_FILE: configFile,
3737
PATH: process.env["PATH"],
3838
},

0 commit comments

Comments
 (0)