From be48fedb972b9d63901303c73c4baa6b46d6646c Mon Sep 17 00:00:00 2001 From: jackwotherspoon Date: Mon, 16 Dec 2024 15:49:21 +0000 Subject: [PATCH] chore: update test --- system-test/tedious-connect.mjs | 101 +++++++++++++++++--------------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/system-test/tedious-connect.mjs b/system-test/tedious-connect.mjs index c77c085..9fd0aa7 100644 --- a/system-test/tedious-connect.mjs +++ b/system-test/tedious-connect.mjs @@ -13,57 +13,62 @@ // limitations under the License. import t from 'tap'; -import { Connector } from '@google-cloud/cloud-sql-connector'; -import { Connection, Request } -t.test( - 'open connection and run basic sqlserver commands', - async t => { - const connector = new Connector(); - const clientOpts = await connector.getTediousOptions({ - instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME, - ipType: 'PUBLIC' - }); - const connection = new Connection({ - server: '0.0.0.0', - authentication: { - type: 'default', - options: { - userName: process.env.SQLSERVER_USER, - password: process.env.SQLSERVER_PASS, - }, - }, +import {Connector} from '@google-cloud/cloud-sql-connector'; +import {Connection, Request} from 'tedious'; + +t.test('open connection and run basic sqlserver commands', async t => { + const connector = new Connector(); + const clientOpts = await connector.getTediousOptions({ + instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME, + ipType: 'PUBLIC', + }); + const connection = new Connection({ + server: '0.0.0.0', + authentication: { + type: 'default', options: { - ...clientOpts, - port: 9999, - database: process.env.SQLSERVER_DB, + userName: process.env.SQLSERVER_USER, + password: process.env.SQLSERVER_PASS, }, - }) + }, + options: { + ...clientOpts, + port: 9999, + database: process.env.SQLSERVER_DB, + }, + }); - await new Promise((res, rej) => { - connection.connect(err => { - if (err) { - return rej(err) - } - res() - }) - }) + await new Promise((res, rej) => { + connection.connect(err => { + if (err) { + return rej(err); + } + res(); + }); + }); - const res = await new Promise((res, rej) => { - let result; - const req = new Request('SELECT GETUTCDATE()', (err) => { - if (err) { - throw err; - } - }) - req.on('error', (err) => { rej(err); }); - req.on('row', (columns) => { result = columns; }); - req.on('requestCompleted', () => { res(result); }); - connection.execSql(req); - }) + const res = await new Promise((res, rej) => { + let result; + const req = new Request('SELECT GETUTCDATE()', err => { + if (err) { + throw err; + } + }); + req.on('error', err => { + rej(err); + }); + req.on('row', columns => { + result = columns; + }); + req.on('requestCompleted', () => { + res(result); + }); + connection.execSql(req); + }); - const [{ value: utcDateResult }] = res; - t.ok(utcDateResult.getTime(), 'should have valid returned date object'); + const [{value: utcDateResult}] = res; + t.ok(utcDateResult.getTime(), 'should have valid returned date object'); - connection.close(); - connector.close(); - }); + connection.close(); + connector.close(); +});