11/* eslint-disable @typescript-eslint/naming-convention */
22
33import assert from "node:assert" ;
4- import { loadConfigFile , resolveConfigFilePath } from "./configFile" ;
4+ import {
5+ HostParsingError ,
6+ isConfigFileParsingError ,
7+ loadConfigFile ,
8+ resolveConfigFilePath ,
9+ TokenParsingError ,
10+ } from "./configFile" ;
511import { writeFile } from "node:fs/promises" ;
612import { withFile } from "tmp-promise" ;
713import { homedir } from "node:os" ;
@@ -48,11 +54,14 @@ token = dapitest54321
4854 const profiles = await loadConfigFile ( path ) ;
4955
5056 assert . equal ( Object . keys ( profiles ) . length , 2 ) ;
57+ assert . ok ( ! isConfigFileParsingError ( profiles . DEFAULT ) ) ;
5158 assert . equal (
5259 profiles . DEFAULT . host . href ,
5360 "https://cloud.databricks.com/"
5461 ) ;
5562 assert . equal ( profiles . DEFAULT . token , "dapitest1234" ) ;
63+
64+ assert . ok ( ! isConfigFileParsingError ( profiles . STAGING ) ) ;
5665 assert . equal (
5766 profiles . STAGING . host . href ,
5867 "https://staging.cloud.databricks.com/"
@@ -78,16 +87,72 @@ token = dapitest54321
7887 const profiles = await loadConfigFile ( path ) ;
7988
8089 assert . equal ( Object . keys ( profiles ) . length , 2 ) ;
90+ assert . ok ( ! isConfigFileParsingError ( profiles . DEFAULT ) ) ;
8191 assert . equal (
8292 profiles . DEFAULT . host . href ,
8393 "https://cloud.databricks.com/"
8494 ) ;
8595 assert . equal ( profiles . DEFAULT . token , "dapitest1234" ) ;
96+
97+ assert . ok ( ! isConfigFileParsingError ( profiles . STAGING ) ) ;
8698 assert . equal (
8799 profiles . STAGING . host . href ,
88100 "https://staging.cloud.databricks.com/"
89101 ) ;
90102 assert . equal ( profiles . STAGING . token , "dapitest54321" ) ;
91103 } ) ;
92104 } ) ;
105+
106+ it ( "should load all valid profiles and return errors for rest" , async ( ) => {
107+ await withFile ( async ( { path} ) => {
108+ await writeFile (
109+ path ,
110+ `[correct]
111+ host = https://cloud.databricks.com/
112+ token = dapitest1234
113+
114+ [no-host]
115+ token = dapitest54321
116+
117+ [wrong-host]
118+ host = wrong
119+ token = dapitest54321
120+
121+ [no-token]
122+ host = https://cloud.databricks.com/
123+
124+ [missing-host-token]
125+ nothing = true
126+ `
127+ ) ;
128+ const profiles = await loadConfigFile ( path ) ;
129+ assert . equal ( Object . keys ( profiles ) . length , 5 ) ;
130+ assert . ok ( ! isConfigFileParsingError ( profiles [ "correct" ] ) ) ;
131+ assert . deepEqual ( profiles [ "correct" ] , {
132+ host : new URL ( "https://cloud.databricks.com/" ) ,
133+ token : "dapitest1234" ,
134+ } ) ;
135+
136+ assert . ok ( isConfigFileParsingError ( profiles [ "no-host" ] ) ) ;
137+ assert . deepEqual (
138+ profiles [ "no-host" ] ,
139+ new HostParsingError ( '"host" it not defined' )
140+ ) ;
141+
142+ assert . ok ( isConfigFileParsingError ( profiles [ "wrong-host" ] ) ) ;
143+ assert . ok ( profiles [ "wrong-host" ] instanceof HostParsingError ) ;
144+
145+ assert . ok ( isConfigFileParsingError ( profiles [ "no-token" ] ) ) ;
146+ assert . deepEqual (
147+ profiles [ "no-token" ] ,
148+ new TokenParsingError ( '"token" it not defined' )
149+ ) ;
150+
151+ assert . ok ( isConfigFileParsingError ( profiles [ "missing-host-token" ] ) ) ;
152+ assert . deepEqual (
153+ profiles [ "missing-host-token" ] ,
154+ new HostParsingError ( '"host" it not defined' )
155+ ) ;
156+ } ) ;
157+ } ) ;
93158} ) ;
0 commit comments