@@ -34,61 +34,65 @@ describe('Protocol Versions E2E Tests', function () {
3434 // These tests might take longer than the default timeout
3535 this . timeout ( 60000 ) ;
3636
37- // Use for...of to iterate through all protocol versions
38- for ( const { version, desc } of protocolVersions ) {
39- describe ( `Protocol ${ desc } ` , function ( ) {
37+ // Instead of using a loop with functions inside, we'll create a function that returns
38+ // a test suite for each protocol version
39+ protocolVersions . forEach ( ( { version, desc } ) => {
40+ describe ( `Protocol ${ desc } ` , ( ) => {
4041 let client : DBSQLClient ;
4142 let session : IDBSQLSession ;
4243
43- before ( async function ( ) {
44- try {
45- client = new DBSQLClient ( ) ;
44+ before ( function ( this : Mocha . Context ) {
45+ return ( async ( ) => {
46+ try {
47+ client = new DBSQLClient ( ) ;
4648
47- // Connect to the Databricks SQL service
48- await client . connect ( {
49- host : config . host ,
50- path : config . path ,
51- token : config . token ,
52- } ) ;
49+ // Connect to the Databricks SQL service
50+ await client . connect ( {
51+ host : config . host ,
52+ path : config . path ,
53+ token : config . token ,
54+ } ) ;
5355
54- // Get access to the driver
55- const getDriverOriginal = client . getDriver . bind ( client ) ;
56-
57- // Stub getDriver to return a proxied version of the driver with overridden openSession
58- sinon . stub ( client , 'getDriver' ) . callsFake ( async ( ) => {
59- const driver = await getDriverOriginal ( ) ;
60-
61- // Create a proxy for the driver to intercept openSession calls
62- const driverProxy = new Proxy ( driver , {
63- get ( target , prop ) {
64- if ( prop === 'openSession' ) {
65- return async ( request : any ) => {
66- // Modify the request to use our specific protocol version
67- const modifiedRequest = {
68- ...request ,
69- client_protocol_i64 : new Int64 ( version ) ,
56+ // Get access to the driver
57+ const getDriverOriginal = client . getDriver . bind ( client ) ;
58+
59+ // Stub getDriver to return a proxied version of the driver with overridden openSession
60+ sinon . stub ( client , 'getDriver' ) . callsFake ( async ( ) => {
61+ const driver = await getDriverOriginal ( ) ;
62+
63+ // Create a proxy for the driver to intercept openSession calls
64+ const driverProxy = new Proxy ( driver , {
65+ get ( target , prop ) {
66+ if ( prop === 'openSession' ) {
67+ return async ( request : any ) => {
68+ // Modify the request to use our specific protocol version
69+ const modifiedRequest = {
70+ ...request ,
71+ client_protocol_i64 : new Int64 ( version ) ,
72+ } ;
73+ return target . openSession ( modifiedRequest ) ;
7074 } ;
71- return target . openSession ( modifiedRequest ) ;
72- } ;
73- }
74- return target [ prop as keyof IDriver ] ;
75- } ,
76- } ) ;
75+ }
76+ return target [ prop as keyof IDriver ] ;
77+ } ,
78+ } ) ;
7779
78- return driverProxy ;
79- } ) ;
80+ return driverProxy ;
81+ } ) ;
8082
81- session = await client . openSession ( {
82- initialCatalog : config . catalog ,
83- initialSchema : config . schema ,
84- } ) ;
85- } catch ( error ) {
86- console . log ( `Failed to open session with protocol version ${ desc } : ${ error } ` ) ;
87- this . skip ( ) ;
88- }
83+ session = await client . openSession ( {
84+ initialCatalog : config . catalog ,
85+ initialSchema : config . schema ,
86+ } ) ;
87+ } catch ( error ) {
88+ // eslint-disable-next-line no-console
89+ console . log ( `Failed to open session with protocol version ${ desc } : ${ error } ` ) ;
90+ this . skip ( ) ;
91+ }
92+ } ) ( ) ;
8993 } ) ;
9094
91- after ( async function ( ) {
95+ after ( async ( ) => {
9296 if ( session ) {
9397 await session . close ( ) ;
9498 }
@@ -99,7 +103,7 @@ describe('Protocol Versions E2E Tests', function () {
99103 sinon . restore ( ) ;
100104 } ) ;
101105
102- it ( 'should handle various data types' , async function ( ) {
106+ it ( 'should handle various data types' , async ( ) => {
103107 // Query testing multiple data types supported by Databricks
104108 const query = `
105109 SELECT
@@ -277,7 +281,7 @@ describe('Protocol Versions E2E Tests', function () {
277281 expect ( row . null_val ) . to . be . null ;
278282 } ) ;
279283
280- it ( 'should get catalogs' , async function ( ) {
284+ it ( 'should get catalogs' , async ( ) => {
281285 const operation = await session . getCatalogs ( ) ;
282286 const catalogs = await operation . fetchAll ( ) ;
283287 await operation . close ( ) ;
@@ -287,7 +291,7 @@ describe('Protocol Versions E2E Tests', function () {
287291 expect ( catalogs [ 0 ] ) . to . have . property ( 'TABLE_CAT' ) ;
288292 } ) ;
289293
290- it ( 'should get schemas' , async function ( ) {
294+ it ( 'should get schemas' , async ( ) => {
291295 const operation = await session . getSchemas ( { catalogName : config . catalog } ) ;
292296 const schemas = await operation . fetchAll ( ) ;
293297 await operation . close ( ) ;
@@ -297,7 +301,7 @@ describe('Protocol Versions E2E Tests', function () {
297301 expect ( schemas [ 0 ] ) . to . have . property ( 'TABLE_SCHEM' ) ;
298302 } ) ;
299303
300- it ( 'should get table types' , async function ( ) {
304+ it ( 'should get table types' , async ( ) => {
301305 const operation = await session . getTableTypes ( ) ;
302306 const tableTypes = await operation . fetchAll ( ) ;
303307 await operation . close ( ) ;
@@ -307,7 +311,7 @@ describe('Protocol Versions E2E Tests', function () {
307311 expect ( tableTypes [ 0 ] ) . to . have . property ( 'TABLE_TYPE' ) ;
308312 } ) ;
309313
310- it ( 'should get tables' , async function ( ) {
314+ it ( 'should get tables' , async ( ) => {
311315 const operation = await session . getTables ( {
312316 catalogName : config . catalog ,
313317 schemaName : config . schema ,
@@ -322,35 +326,38 @@ describe('Protocol Versions E2E Tests', function () {
322326 }
323327 } ) ;
324328
325- it ( 'should get columns from current schema' , async function ( ) {
326- // First get a table name from the current schema
327- const tablesOp = await session . getTables ( {
328- catalogName : config . catalog ,
329- schemaName : config . schema ,
330- } ) ;
331- const tables = await tablesOp . fetchAll ( ) ;
332- await tablesOp . close ( ) ;
333-
334- if ( tables . length === 0 ) {
335- console . log ( 'No tables found in the schema, skipping column test' ) ;
336- this . skip ( ) ;
337- return ;
338- }
339-
340- const tableName = ( tables [ 0 ] as any ) . TABLE_NAME ;
341-
342- const operation = await session . getColumns ( {
343- catalogName : config . catalog ,
344- schemaName : config . schema ,
345- tableName,
346- } ) ;
347- const columns = await operation . fetchAll ( ) ;
348- await operation . close ( ) ;
329+ it ( 'should get columns from current schema' , function ( this : Mocha . Context ) {
330+ return ( async ( ) => {
331+ // First get a table name from the current schema
332+ const tablesOp = await session . getTables ( {
333+ catalogName : config . catalog ,
334+ schemaName : config . schema ,
335+ } ) ;
336+ const tables = await tablesOp . fetchAll ( ) ;
337+ await tablesOp . close ( ) ;
338+
339+ if ( tables . length === 0 ) {
340+ // eslint-disable-next-line no-console
341+ console . log ( 'No tables found in the schema, skipping column test' ) ;
342+ this . skip ( ) ;
343+ return ;
344+ }
345+
346+ const tableName = ( tables [ 0 ] as any ) . TABLE_NAME ;
347+
348+ const operation = await session . getColumns ( {
349+ catalogName : config . catalog ,
350+ schemaName : config . schema ,
351+ tableName,
352+ } ) ;
353+ const columns = await operation . fetchAll ( ) ;
354+ await operation . close ( ) ;
349355
350- expect ( columns ) . to . be . an ( 'array' ) ;
351- expect ( columns . length ) . to . be . at . least ( 1 ) ;
352- expect ( columns [ 0 ] ) . to . have . property ( 'COLUMN_NAME' ) ;
356+ expect ( columns ) . to . be . an ( 'array' ) ;
357+ expect ( columns . length ) . to . be . at . least ( 1 ) ;
358+ expect ( columns [ 0 ] ) . to . have . property ( 'COLUMN_NAME' ) ;
359+ } ) ( ) ;
353360 } ) ;
354361 } ) ;
355- }
362+ } ) ;
356363} ) ;
0 commit comments