Skip to content

Commit

Permalink
Test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadraju committed Jun 20, 2023
1 parent 8377cca commit 9617b45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The test suite uses [mocha](https://www.npmjs.com/package/mocha),
Set the following environment variables to provide credentials for the test suite.

* `NODE_ORACLEDB_USER` provides the username of the schema user which you used for testing.
Use the username prefix 'NJS_' when creating a new user inside the test suite. Test suite does create such users.
Use the parameter *createUser* specified in `test/dbconfig.js` to create a new user within the test suite. Test suite does create such users.

* `NODE_ORACLEDB_PASSWORD` provides the password of the schema user which you used for testing.
if you're generating a password for the user, use the predefined function testsUtil.generateRandomPassword.
Expand Down
2 changes: 1 addition & 1 deletion test/changePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('161. changePassword.js', function() {
let DBA_config;
let dbaConn;
let sql;
const myUser = dbConfig.user + "_cpw";
const myUser = dbConfig.createUser();
if (dbConfig.test.DBA_PRIVILEGE == true) {
DBA_config = {
user: dbConfig.test.DBA_user,
Expand Down
6 changes: 6 additions & 0 deletions test/dbconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const config = {
}
};

let counter = 0;

if (process.env.NODE_ORACLEDB_CONNECTIONSTRING) {
config.connectString = process.env.NODE_ORACLEDB_CONNECTIONSTRING;
} else {
Expand Down Expand Up @@ -150,4 +152,8 @@ if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
console.log("Thin mode selected");
}

config.createUser = () => {
++counter;
return "NJS_" + counter.toString() + config.user;
};
module.exports = config;
20 changes: 11 additions & 9 deletions test/jsonDualityViews1.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,13 @@ describe('272. jsonDualityView1.js', function() {
describe('272.3.11 Create view without privilege ', function() {
let connection = null;
let conn = null;
const user1 = dbConfig.createUser();
const user2 = dbConfig.createUser();
const pwd = testsUtil.generateRandomPassword();
const createUser1 = `create user njs_test1 identified by ${pwd}`;
const createUser2 = `create user njs_test2 identified by ${pwd}`;
const grantPriv1 = `grant create session, resource, connect, unlimited tablespace to njs_test1`;
const grantPriv2 = `grant create session to njs_test2`;
const createUser1 = `create user ${user1} identified by ${pwd}`;
const createUser2 = `create user ${user2} identified by ${pwd}`;
const grantPriv1 = `grant create session, resource, connect, unlimited tablespace to ${user1}`;
const grantPriv2 = `grant create session to ${user2}`;

const createTableStudent = `create table student(
stuid number,
Expand Down Expand Up @@ -774,8 +776,8 @@ describe('272. jsonDualityView1.js', function() {
if (dbConfig.test.drcp || dbConfig.test.isCmanTdm) {
return;
}
await connection.execute(`drop user njs_test1 cascade`);
await connection.execute(`drop user njs_test2 cascade`);
await connection.execute(`drop user ${user1} cascade`);
await connection.execute(`drop user ${user2} cascade`);
await connection.close();
});

Expand All @@ -785,7 +787,7 @@ describe('272. jsonDualityView1.js', function() {
AS
student @insert @update @delete
{StudentId: stuid, StudentName: name}`;
conn = await oracledb.getConnection({user: 'njs_test1',
conn = await oracledb.getConnection({user: user1,
password: pwd,
connectString: dbConfig.connectString
});
Expand All @@ -807,13 +809,13 @@ describe('272. jsonDualityView1.js', function() {

it('272.3.11.2 Query with test2 user', async function() {

conn = await oracledb.getConnection({user: 'njs_test2',
conn = await oracledb.getConnection({user: user2,
password: pwd,
connectString: dbConfig.connectString
});

await assert.rejects(
async () => await conn.execute(`select * from njs_test1.student_ov`),
async () => await conn.execute(`select * from ${user1}.student_ov`),
/ORA-00942:/ //ORA-00942: table or view does not exist
);
await conn.close();
Expand Down

0 comments on commit 9617b45

Please sign in to comment.