diff --git a/.eslintignore b/.eslintignore index 2dd688c0..b2ee35a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ dist/ +dist-test/ scripts/ diff --git a/package.json b/package.json index bdd656f0..55e6598b 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ ], "license": "Apache-2.0", "scripts": { - "clean": "rm -rf dist", - "compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json", + "clean": "rm -rf dist ; rm -rf dist-test", + "compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json && tsc -p tsconfig-systemtest.json && tsc -p tsconfig-systemtest-esm.json", "prepare": "rm -rf dist && npm run compile && node ./scripts/fixup.cjs", "pretest": "npm run prepare", "presnap": "npm run prepare", @@ -88,4 +88,4 @@ "google-auth-library": "^9.2.0", "p-throttle": "^7.0.0" } -} \ No newline at end of file +} diff --git a/scripts/fixup.cjs b/scripts/fixup.cjs index baa16e53..c1f5dab8 100644 --- a/scripts/fixup.cjs +++ b/scripts/fixup.cjs @@ -20,6 +20,8 @@ const {readdir, readFile, writeFile} = require('node:fs/promises'); const cjsDistFolder = resolve(__dirname, '../dist/cjs'); const mjsDistFolder = resolve(__dirname, '../dist/mjs'); +const cjsSystemTestDistFolder = resolve(__dirname, '../dist-test/cjs'); +const mjsSystemTestDistFolder = resolve(__dirname, '../dist-test/mjs'); async function addModuleSystemTypeFile() { await writeFile( @@ -31,6 +33,15 @@ async function addModuleSystemTypeFile() { resolve(mjsDistFolder, 'package.json'), JSON.stringify({ type: 'module' }) ); + await writeFile( + resolve(cjsSystemTestDistFolder, 'package.json'), + JSON.stringify({ type: 'commonjs' }) + ); + + await writeFile( + resolve(mjsSystemTestDistFolder, 'package.json'), + JSON.stringify({ type: 'module' }) + ); } async function fixupImportFileExtensions() { diff --git a/system-test/mysql-tests.ts b/system-test/mysql-tests.ts new file mode 100644 index 00000000..cc140419 --- /dev/null +++ b/system-test/mysql-tests.ts @@ -0,0 +1,61 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +function mysqlTests(t, connectorModule, mysql2PromiseModule) { + const mysql = mysql2PromiseModule; + const {Connector, AuthTypes, IpAddressTypes} = connectorModule; + + t.test('open connection and run basic mysql commands', async t => { + const connector = new Connector(); + const clientOpts = await connector.getOptions({ + instanceConnectionName: String(process.env.MYSQL_CONNECTION_NAME), + }); + const conn = await mysql.createConnection({ + ...clientOpts, + user: String(process.env.MYSQL_USER), + password: String(process.env.MYSQL_PASS), + database: String(process.env.MYSQL_DB), + }); + + const [result] = await conn.query('SELECT NOW();'); + const [row] = result; + const returnedDate = row['NOW()']; + t.ok(returnedDate.getTime(), 'should have valid returned date object'); + + await conn.end(); + connector.close(); + }); + + t.test('open IAM connection and run basic mysql commands', async t => { + const connector = new Connector(); + const clientOpts = await connector.getOptions({ + instanceConnectionName: String(process.env.MYSQL_IAM_CONNECTION_NAME), + ipType: IpAddressTypes.PUBLIC, + authType: AuthTypes.IAM, + }); + const conn = await mysql.createConnection({ + ...clientOpts, + user: String(process.env.MYSQL_IAM_USER), + database: String(process.env.MYSQL_DB), + }); + + const [[result]] = await conn.query('SELECT NOW();'); + const returnedDate = result['NOW()']; + t.ok(returnedDate.getTime(), 'should have valid returned date object'); + + await conn.end(); + connector.close(); + }); +} +export {mysqlTests}; diff --git a/system-test/mysql2-connect.cjs b/system-test/mysql2-connect.cjs deleted file mode 100644 index 83aabe85..00000000 --- a/system-test/mysql2-connect.cjs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const t = require('tap'); -const mysql = require('mysql2/promise'); -const {Connector} = require('@google-cloud/cloud-sql-connector'); - -t.test('open connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.MYSQL_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: process.env.MYSQL_USER, - password: process.env.MYSQL_PASS, - database: process.env.MYSQL_DB, - }); - - const [[result]] = await conn.query('SELECT NOW();'); - const returnedDate = result['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); - -t.test('open IAM connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'IAM', - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: process.env.MYSQL_IAM_USER, - database: process.env.MYSQL_DB, - }); - - const [[result]] = await conn.query('SELECT NOW();'); - const returnedDate = result['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); diff --git a/system-test/mysql2-connect.mjs b/system-test/mysql2-connect.mjs deleted file mode 100644 index b590e17d..00000000 --- a/system-test/mysql2-connect.mjs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -import mysql from 'mysql2/promise'; -import {Connector} from '@google-cloud/cloud-sql-connector'; - -t.test('open connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.MYSQL_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: process.env.MYSQL_USER, - password: process.env.MYSQL_PASS, - database: process.env.MYSQL_DB, - }); - - const [[result]] = await conn.query('SELECT NOW();'); - const returnedDate = result['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); - -t.test('open IAM connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'IAM', - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: process.env.MYSQL_IAM_USER, - database: process.env.MYSQL_DB, - }); - - const [[result]] = await conn.query('SELECT NOW();'); - const returnedDate = result['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); diff --git a/system-test/mysql2-connect.ts b/system-test/mysql2-connect.ts deleted file mode 100644 index 71d04593..00000000 --- a/system-test/mysql2-connect.ts +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -import {RowDataPacket} from 'mysql2'; -import mysql from 'mysql2/promise'; -import { - Connector, - AuthTypes, - IpAddressTypes, -} from '@google-cloud/cloud-sql-connector'; - -interface Now extends RowDataPacket { - 'NOW()': Date; -} - -t.test('open connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: String(process.env.MYSQL_CONNECTION_NAME), - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: String(process.env.MYSQL_USER), - password: String(process.env.MYSQL_PASS), - database: String(process.env.MYSQL_DB), - }); - - const [result] = await conn.query('SELECT NOW();'); - const [row] = result; - const returnedDate = row['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); - -t.test('open IAM connection and run basic mysql commands', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: String(process.env.MYSQL_IAM_CONNECTION_NAME), - ipType: IpAddressTypes.PUBLIC, - authType: AuthTypes.IAM, - }); - const conn = await mysql.createConnection({ - ...clientOpts, - user: String(process.env.MYSQL_IAM_USER), - database: String(process.env.MYSQL_DB), - }); - - const [[result]] = await conn.query('SELECT NOW();'); - const returnedDate = result['NOW()']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await conn.end(); - connector.close(); -}); diff --git a/system-test/pg-connect.cjs b/system-test/pg-connect.cjs deleted file mode 100644 index 601b07ce..00000000 --- a/system-test/pg-connect.cjs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const t = require('tap'); -const pg = require('pg'); -const {Connector} = require('@google-cloud/cloud-sql-connector'); -const {Client} = pg; - -t.test('open connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_USER, - password: process.env.POSTGRES_PASS, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test('open IAM connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_IAM_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'IAM', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_IAM_USER, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test( - 'open connection to CAS-based CA instance and retrieves standard pg tables', - async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_CAS_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_USER, - password: process.env.POSTGRES_CAS_PASS, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); - } -); diff --git a/system-test/pg-connect.mjs b/system-test/pg-connect.mjs deleted file mode 100644 index 4b7fec05..00000000 --- a/system-test/pg-connect.mjs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -import pg from 'pg'; -import {Connector} from '@google-cloud/cloud-sql-connector'; -const {Client} = pg; - -t.test('open connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_USER, - password: process.env.POSTGRES_PASS, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test('open IAM connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_IAM_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'IAM', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_IAM_USER, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test( - 'open connection to CAS-based CA instance and retrieves standard pg tables', - async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: process.env.POSTGRES_CAS_CONNECTION_NAME, - ipType: 'PUBLIC', - authType: 'PASSWORD', - }); - const client = new Client({ - ...clientOpts, - user: process.env.POSTGRES_USER, - password: process.env.POSTGRES_CAS_PASS, - database: process.env.POSTGRES_DB, - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); - } -); diff --git a/system-test/pg-connect.ts b/system-test/pg-connect.ts deleted file mode 100644 index de10d0b2..00000000 --- a/system-test/pg-connect.ts +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -import pg from 'pg'; -import { - Connector, - AuthTypes, - IpAddressTypes, -} from '@google-cloud/cloud-sql-connector'; -const {Client} = pg; - -t.test('open connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: String(process.env.POSTGRES_CONNECTION_NAME), - }); - const client = new Client({ - ...clientOpts, - user: String(process.env.POSTGRES_USER), - password: String(process.env.POSTGRES_PASS), - database: String(process.env.POSTGRES_DB), - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test('open IAM connection and retrieves standard pg tables', async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: String(process.env.POSTGRES_IAM_CONNECTION_NAME), - ipType: IpAddressTypes.PUBLIC, - authType: AuthTypes.IAM, - }); - const client = new Client({ - ...clientOpts, - user: String(process.env.POSTGRES_IAM_USER), - database: String(process.env.POSTGRES_DB), - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); -}); - -t.test( - 'open connection to CAS-based CA instance and retrieves standard pg tables', - async t => { - const connector = new Connector(); - const clientOpts = await connector.getOptions({ - instanceConnectionName: String(process.env.POSTGRES_CAS_CONNECTION_NAME), - }); - const client = new Client({ - ...clientOpts, - user: String(process.env.POSTGRES_USER), - password: String(process.env.POSTGRES_CAS_PASS), - database: String(process.env.POSTGRES_DB), - }); - client.connect(); - - const { - rows: [result], - } = await client.query('SELECT NOW();'); - const returnedDate = result['now']; - t.ok(returnedDate.getTime(), 'should have valid returned date object'); - - await client.end(); - connector.close(); - } -); diff --git a/system-test/pg-tests.ts b/system-test/pg-tests.ts new file mode 100644 index 00000000..9ce1d701 --- /dev/null +++ b/system-test/pg-tests.ts @@ -0,0 +1,96 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +function pgTests(t, connectorModule, pgModule) { + // Dereference the connector module + const {Connector, AuthTypes, IpAddressTypes} = connectorModule; + const {Client} = pgModule; + + t.test('open connection and retrieves standard pg tables', async t => { + const connector = new Connector(); + const clientOpts = await connector.getOptions({ + instanceConnectionName: String(process.env.POSTGRES_CONNECTION_NAME), + }); + const client = new Client({ + ...clientOpts, + user: String(process.env.POSTGRES_USER), + password: String(process.env.POSTGRES_PASS), + database: String(process.env.POSTGRES_DB), + }); + client.connect(); + + const { + rows: [result], + } = await client.query('SELECT NOW();'); + const returnedDate = result['now']; + t.ok(returnedDate.getTime(), 'should have valid returned date object'); + + await client.end(); + connector.close(); + }); + + t.test('open IAM connection and retrieves standard pg tables', async t => { + const connector = new Connector(); + const clientOpts = await connector.getOptions({ + instanceConnectionName: String(process.env.POSTGRES_IAM_CONNECTION_NAME), + ipType: IpAddressTypes.PUBLIC, + authType: AuthTypes.IAM, + }); + const client = new Client({ + ...clientOpts, + user: String(process.env.POSTGRES_IAM_USER), + database: String(process.env.POSTGRES_DB), + }); + client.connect(); + + const { + rows: [result], + } = await client.query('SELECT NOW();'); + const returnedDate = result['now']; + t.ok(returnedDate.getTime(), 'should have valid returned date object'); + + await client.end(); + connector.close(); + }); + + t.test( + 'open connection to CAS-based CA instance and retrieves standard pg tables', + async t => { + const connector = new Connector(); + const clientOpts = await connector.getOptions({ + instanceConnectionName: String( + process.env.POSTGRES_CAS_CONNECTION_NAME + ), + }); + const client = new Client({ + ...clientOpts, + user: String(process.env.POSTGRES_USER), + password: String(process.env.POSTGRES_CAS_PASS), + database: String(process.env.POSTGRES_DB), + }); + client.connect(); + + const { + rows: [result], + } = await client.query('SELECT NOW();'); + const returnedDate = result['now']; + t.ok(returnedDate.getTime(), 'should have valid returned date object'); + + await client.end(); + connector.close(); + } + ); +} + +export {pgTests}; diff --git a/system-test/system.cjs b/system-test/system.cjs new file mode 100644 index 00000000..a06207f9 --- /dev/null +++ b/system-test/system.cjs @@ -0,0 +1,27 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const t = require('tap'); +const pg = require('pg'); +const mysql = require('mysql2/promise'); +const tedious = require('tedious'); + +const connector = require('@google-cloud/cloud-sql-connector'); +const {pgTests} = require("../dist-test/cjs/pg-tests.js"); +const {mysqlTests} = require("../dist-test/cjs/mysql-tests.js"); +const {tediousTests} = require("../dist-test/cjs/tedious-tests.js"); + +pgTests(t, connector, pg) +mysqlTests(t, connector, mysql) +tediousTests(t, connector, tedious) diff --git a/system-test/system.mjs b/system-test/system.mjs new file mode 100644 index 00000000..2fa4bd58 --- /dev/null +++ b/system-test/system.mjs @@ -0,0 +1,30 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import t from 'tap'; +import pg from 'pg'; +import mysql from 'mysql2/promise'; +import {Connection, Request} from 'tedious'; + +import {Connector, AuthTypes, IpAddressTypes} from '@google-cloud/cloud-sql-connector'; + +import {pgTests} from "../dist-test/mjs/pg-tests.js"; +import {mysqlTests} from "../dist-test/mjs/mysql-tests.js"; +import {tediousTests} from "../dist-test/mjs/tedious-tests.js"; + +const connectorModule = {Connector, AuthTypes, IpAddressTypes} + +pgTests(t, connectorModule, pg) +mysqlTests(t, connectorModule, mysql) +tediousTests(t, connectorModule, {Connection, Request}) diff --git a/system-test/system.ts b/system-test/system.ts new file mode 100644 index 00000000..f2b86814 --- /dev/null +++ b/system-test/system.ts @@ -0,0 +1,33 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import t from 'tap'; +import pg from 'pg'; +import mysql from 'mysql2/promise'; +import {Connection, Request} from 'tedious'; + +import { + Connector, + AuthTypes, + IpAddressTypes, +} from '@google-cloud/cloud-sql-connector'; +const connectorModule = {Connector, AuthTypes, IpAddressTypes}; + +import {pgTests} from './pg-tests'; +import {mysqlTests} from './mysql-tests'; +import {tediousTests} from './tedious-tests'; + +pgTests(t, connectorModule, pg); +mysqlTests(t, connectorModule, mysql); +tediousTests(t, connectorModule, {Connection, Request}); diff --git a/system-test/tedious-connect.cjs b/system-test/tedious-connect.cjs deleted file mode 100644 index f2ead835..00000000 --- a/system-test/tedious-connect.cjs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const t = require('tap'); -const {Connector} = require('@google-cloud/cloud-sql-connector'); -const {Connection, Request} = require('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: { - 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(); - }); - }); - - 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'); - - connection.close(); - connector.close(); -}); diff --git a/system-test/tedious-connect.mjs b/system-test/tedious-connect.mjs deleted file mode 100644 index 9fd0aa73..00000000 --- a/system-test/tedious-connect.mjs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -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: { - 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(); - }); - }); - - 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'); - - connection.close(); - connector.close(); -}); diff --git a/system-test/tedious-connect.ts b/system-test/tedious-connect.ts deleted file mode 100644 index e789e273..00000000 --- a/system-test/tedious-connect.ts +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import t from 'tap'; -import {Connector, IpAddressTypes} 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: String(process.env.SQLSERVER_CONNECTION_NAME), - ipType: IpAddressTypes.PUBLIC, - }); - const connection = new Connection({ - server: '0.0.0.0', - authentication: { - type: 'default', - options: { - userName: String(process.env.SQLSERVER_USER), - password: String(process.env.SQLSERVER_PASS), - }, - }, - options: { - ...clientOpts, - port: 9999, - database: String(process.env.SQLSERVER_DB), - }, - }); - - await new Promise((res, rej) => { - connection.connect(err => { - if (err) { - return rej(err); - } - res(null); - }); - }); - - type ColumnValue = import('tedious').ColumnValue; - const res: ColumnValue[] = await new Promise((res, rej) => { - let result: ColumnValue[]; - 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'); - - connection.close(); - connector.close(); -}); diff --git a/system-test/tedious-tests.ts b/system-test/tedious-tests.ts new file mode 100644 index 00000000..10622ad9 --- /dev/null +++ b/system-test/tedious-tests.ts @@ -0,0 +1,77 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +function tediousTests(t, connectorModule, tediousModule) { + const {Connector, IpAddressTypes} = connectorModule; + const {Connection, Request} = tediousModule; + + t.test('open connection and run basic sqlserver commands', async t => { + const connector = new Connector(); + const clientOpts = await connector.getTediousOptions({ + instanceConnectionName: String(process.env.SQLSERVER_CONNECTION_NAME), + ipType: IpAddressTypes.PUBLIC, + }); + const connection = new Connection({ + server: '0.0.0.0', + authentication: { + type: 'default', + options: { + userName: String(process.env.SQLSERVER_USER), + password: String(process.env.SQLSERVER_PASS), + }, + }, + options: { + ...clientOpts, + port: 9999, + database: String(process.env.SQLSERVER_DB), + }, + }); + + await new Promise((res, rej) => { + connection.connect(err => { + if (err) { + return rej(err); + } + res(null); + }); + }); + + type ColumnValue = import('tedious').ColumnValue; + const res: ColumnValue[] = await new Promise((res, rej) => { + let result: ColumnValue[]; + 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'); + + connection.close(); + connector.close(); + }); +} +export {tediousTests}; diff --git a/tsconfig-systemtest-esm.json b/tsconfig-systemtest-esm.json new file mode 100644 index 00000000..2e5aa316 --- /dev/null +++ b/tsconfig-systemtest-esm.json @@ -0,0 +1,23 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "exclude": [ + "./test", + "./tap-snapshots" + ], + "include": [ + "system-test/pg-tests.ts", + "system-test/mysql-tests.ts", + "system-test/tedious-tests.ts" + ], + "compilerOptions": { + "resolveJsonModule": true, + "declarationMap": true, + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "noImplicitAny": false, + "outDir": "dist-test/mjs", + "module": "esnext", + "moduleResolution": "node", + } +} diff --git a/tsconfig-systemtest.json b/tsconfig-systemtest.json new file mode 100644 index 00000000..768ef4d7 --- /dev/null +++ b/tsconfig-systemtest.json @@ -0,0 +1,18 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "exclude": ["./test", "./tap-snapshots"], + "include": [ + "system-test/pg-tests.ts", + "system-test/mysql-tests.ts", + "system-test/tedious-tests.ts" + ], + "compilerOptions": { + "declarationMap": true, + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "noImplicitAny": false, + "module": "node16", + "outDir": "dist-test/cjs" + } +}