Skip to content

Commit

Permalink
chore: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Dec 16, 2024
1 parent f6bfc09 commit be48fed
Showing 1 changed file with 53 additions and 48 deletions.
101 changes: 53 additions & 48 deletions system-test/tedious-connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit be48fed

Please sign in to comment.