|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | import t from 'tap'; |
16 | | -import { Connector } from '@google-cloud/cloud-sql-connector'; |
17 | | -import { Connection, Request } |
18 | | -t.test( |
19 | | - 'open connection and run basic sqlserver commands', |
20 | | - async t => { |
21 | | - const connector = new Connector(); |
22 | | - const clientOpts = await connector.getTediousOptions({ |
23 | | - instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME, |
24 | | - ipType: 'PUBLIC' |
25 | | - }); |
26 | | - const connection = new Connection({ |
27 | | - server: '0.0.0.0', |
28 | | - authentication: { |
29 | | - type: 'default', |
30 | | - options: { |
31 | | - userName: process.env.SQLSERVER_USER, |
32 | | - password: process.env.SQLSERVER_PASS, |
33 | | - }, |
34 | | - }, |
| 16 | +import {Connector} from '@google-cloud/cloud-sql-connector'; |
| 17 | +import {Connection, Request} from 'tedious'; |
| 18 | + |
| 19 | +t.test('open connection and run basic sqlserver commands', async t => { |
| 20 | + const connector = new Connector(); |
| 21 | + const clientOpts = await connector.getTediousOptions({ |
| 22 | + instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME, |
| 23 | + ipType: 'PUBLIC', |
| 24 | + }); |
| 25 | + const connection = new Connection({ |
| 26 | + server: '0.0.0.0', |
| 27 | + authentication: { |
| 28 | + type: 'default', |
35 | 29 | options: { |
36 | | - ...clientOpts, |
37 | | - port: 9999, |
38 | | - database: process.env.SQLSERVER_DB, |
| 30 | + userName: process.env.SQLSERVER_USER, |
| 31 | + password: process.env.SQLSERVER_PASS, |
39 | 32 | }, |
40 | | - }) |
| 33 | + }, |
| 34 | + options: { |
| 35 | + ...clientOpts, |
| 36 | + port: 9999, |
| 37 | + database: process.env.SQLSERVER_DB, |
| 38 | + }, |
| 39 | + }); |
41 | 40 |
|
42 | | - await new Promise((res, rej) => { |
43 | | - connection.connect(err => { |
44 | | - if (err) { |
45 | | - return rej(err) |
46 | | - } |
47 | | - res() |
48 | | - }) |
49 | | - }) |
| 41 | + await new Promise((res, rej) => { |
| 42 | + connection.connect(err => { |
| 43 | + if (err) { |
| 44 | + return rej(err); |
| 45 | + } |
| 46 | + res(); |
| 47 | + }); |
| 48 | + }); |
50 | 49 |
|
51 | | - const res = await new Promise((res, rej) => { |
52 | | - let result; |
53 | | - const req = new Request('SELECT GETUTCDATE()', (err) => { |
54 | | - if (err) { |
55 | | - throw err; |
56 | | - } |
57 | | - }) |
58 | | - req.on('error', (err) => { rej(err); }); |
59 | | - req.on('row', (columns) => { result = columns; }); |
60 | | - req.on('requestCompleted', () => { res(result); }); |
61 | | - connection.execSql(req); |
62 | | - }) |
| 50 | + const res = await new Promise((res, rej) => { |
| 51 | + let result; |
| 52 | + const req = new Request('SELECT GETUTCDATE()', err => { |
| 53 | + if (err) { |
| 54 | + throw err; |
| 55 | + } |
| 56 | + }); |
| 57 | + req.on('error', err => { |
| 58 | + rej(err); |
| 59 | + }); |
| 60 | + req.on('row', columns => { |
| 61 | + result = columns; |
| 62 | + }); |
| 63 | + req.on('requestCompleted', () => { |
| 64 | + res(result); |
| 65 | + }); |
| 66 | + connection.execSql(req); |
| 67 | + }); |
63 | 68 |
|
64 | | - const [{ value: utcDateResult }] = res; |
65 | | - t.ok(utcDateResult.getTime(), 'should have valid returned date object'); |
| 69 | + const [{value: utcDateResult}] = res; |
| 70 | + t.ok(utcDateResult.getTime(), 'should have valid returned date object'); |
66 | 71 |
|
67 | | - connection.close(); |
68 | | - connector.close(); |
69 | | - }); |
| 72 | + connection.close(); |
| 73 | + connector.close(); |
| 74 | +}); |
0 commit comments