|
| 1 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 2 | + |
| 3 | +import assert = require("node:assert"); |
| 4 | +import {loadConfigFile, resolveConfigFilePath} from "./configFile"; |
| 5 | +import {writeFile} from "node:fs/promises"; |
| 6 | +import {withFile} from "tmp-promise"; |
| 7 | +import {homedir} from "node:os"; |
| 8 | +import path = require("node:path"); |
| 9 | + |
| 10 | +describe(__filename, () => { |
| 11 | + beforeEach(() => { |
| 12 | + delete process.env.DATABRICKS_CONFIG_FILE; |
| 13 | + }); |
| 14 | + |
| 15 | + it("should load file from default location", () => { |
| 16 | + assert.equal( |
| 17 | + resolveConfigFilePath(), |
| 18 | + path.join(homedir(), ".databrickscfg") |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should load file location defined in environment variable", () => { |
| 23 | + process.env.DATABRICKS_CONFIG_FILE = "/tmp/databrickscfg.yml"; |
| 24 | + assert.equal(resolveConfigFilePath(), "/tmp/databrickscfg.yml"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should load file from passed in location", () => { |
| 28 | + assert.equal( |
| 29 | + resolveConfigFilePath("/tmp/.databrickscfg"), |
| 30 | + "/tmp/.databrickscfg" |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should parse a config file", async () => { |
| 35 | + await withFile(async ({path}) => { |
| 36 | + await writeFile( |
| 37 | + path, |
| 38 | + `[DEFAULT] |
| 39 | +host = https://cloud.databricks.com/ |
| 40 | +token = dapitest1234 |
| 41 | +
|
| 42 | +[STAGING] |
| 43 | +host = https://staging.cloud.databricks.com/ |
| 44 | +token = dapitest54321` |
| 45 | + ); |
| 46 | + |
| 47 | + const profiles = await loadConfigFile(path); |
| 48 | + |
| 49 | + assert.equal(Object.keys(profiles).length, 2); |
| 50 | + assert.equal( |
| 51 | + profiles.DEFAULT.host.href, |
| 52 | + "https://cloud.databricks.com/" |
| 53 | + ); |
| 54 | + assert.equal(profiles.DEFAULT.token, "dapitest1234"); |
| 55 | + assert.equal( |
| 56 | + profiles.STAGING.host.href, |
| 57 | + "https://staging.cloud.databricks.com/" |
| 58 | + ); |
| 59 | + assert.equal(profiles.STAGING.token, "dapitest54321"); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments