node-oracledb/test/hooks.js

91 lines
3.5 KiB
JavaScript
Raw Normal View History

2023-02-21 12:21:57 +08:00
/* Copyright (c) 2023, Oracle and/or its affiliates. */
2019-03-13 08:00:17 +08:00
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
2019-03-13 08:00:17 +08:00
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2019-03-13 08:00:17 +08:00
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
2019-03-13 08:00:17 +08:00
*
* 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.
2019-03-13 08:00:17 +08:00
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
2023-02-21 12:21:57 +08:00
* hooks.js
2019-03-13 08:00:17 +08:00
*
* DESCRIPTION
2023-02-21 12:21:57 +08:00
* This file contains the global hooks for running the Mocha test suite. It
* verifies the database configuration before running the test suite in order
* to avoid unusual errors. It also sets up information about the database
* (such as whether the database is running in a cloud service or not) which
* may be used in the test suite.
2019-03-13 08:00:17 +08:00
*
*****************************************************************************/
2019-02-08 09:55:21 +08:00
const oracledb = require('oracledb');
2023-02-21 12:04:16 +08:00
const dbConfig = require('./dbconfig.js');
2023-02-21 12:21:57 +08:00
const assert = require('assert');
2019-02-08 09:55:21 +08:00
2023-02-21 12:04:16 +08:00
async function testConnection(description, additionalOptions = {}) {
console.log(description);
2019-02-08 09:55:21 +08:00
2023-02-21 12:04:16 +08:00
const credential = {...dbConfig, ...additionalOptions};
const connection = await oracledb.getConnection(credential);
const result = await connection.execute(
"select * from dual", [], { outFormat: oracledb.OUT_FORMAT_ARRAY });
assert.strictEqual(result.rows[0][0], "X");
await connection.close();
2019-02-08 09:55:21 +08:00
}
/*
* This is to skip tests that are not supported by Oracle Connection Manager in Traffic Director mode.
*/
async function cmanTdmCheck() {
const connection = await oracledb.getConnection(dbConfig);
2023-08-17 16:11:49 +08:00
const result = await connection.execute(`select sys_context('USERENV','PROXY_USER') from dual`);
if (!process.env.NODE_ORACLEDB_PROXY_SESSION_USER && result.rows[0][0] != null) {
dbConfig.test.isCmanTdm = true;
}
await connection.close();
}
2023-02-21 12:21:57 +08:00
async function cloudServiceCheck() {
const connection = await oracledb.getConnection(dbConfig);
2023-03-14 14:33:48 +08:00
// 'userenv' parameter is only available from Oracle DB 18c & later versions
if (connection.oracleServerVersion >= 1800000000) {
2023-08-17 16:11:49 +08:00
const result = await connection.execute("select \
2023-03-14 14:33:48 +08:00
sys_context('userenv', 'cloud_service') from dual");
if (result.rows[0][0]) {
dbConfig.test.isCloudService = true;
}
2023-02-21 12:21:57 +08:00
}
await connection.close();
}
2023-02-21 11:20:36 +08:00
before(async function() {
2023-02-21 12:04:16 +08:00
await testConnection("Regular connection");
if (dbConfig.test.DBA_PRIVILEGE) {
await testConnection("DBA connection", {user: dbConfig.test.DBA_user, password: dbConfig.test.DBA_password, privilege: oracledb.SYSDBA});
}
if (dbConfig.test.externalAuth) {
await testConnection("External auth", {externalAuth: true});
}
if (dbConfig.test.proxySessionUser) {
await testConnection("Proxy Session User", {user: `${dbConfig.user}[${dbConfig.test.proxySessionUser}]`});
}
2023-02-21 12:21:57 +08:00
await cloudServiceCheck();
await cmanTdmCheck();
2021-02-10 15:41:09 +08:00
});