Refactor tests

This commit is contained in:
Christopher Jones 2023-02-21 14:55:40 +11:00
parent 6ae049f31a
commit e82cae24f3
7 changed files with 266 additions and 403 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2022, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -34,8 +34,6 @@
const oracledb = require('oracledb');
const assert = require('assert');
const asyncMiddleware = async () => {
await oracledb.getConnection({connectString: 'doesnotexist.oracle.com'});
};
@ -43,54 +41,49 @@ const asyncMiddleware = async () => {
describe('263. asyncStack.js', () => {
it('263.1 stack on error in getConnection', async () => {
try {
await asyncMiddleware();
} catch (e) {
assert.strictEqual(e.errorNum, 12154); // TNS:could not resolve the connect identifier specified
assert.ok(e.stack.includes('asyncStack.js:40:'), e.stack);
assert.ok(e.stack.includes('asyncStack.js:47:'), e.stack);
}
await assert.rejects(
async () => await asyncMiddleware(),
(e) => {
assert.ok(e.stack.includes('asyncStack.js:38:'), e.stack);
assert.ok(e.stack.includes('asyncStack.js:45:'), e.stack);
return true;
}
);
});
it('263.2 stack on error in createPool', async () => {
let pool = null;
const dbconfig = {
const config = {
user : "asterix",
password : "oblix",
connectString : 'doesnotexist.oracle.com',
poolMin : 1,
poolMax : 50,
poolIncrement : 5
poolIncrement : 5
};
try {
pool = await oracledb.createPool(dbconfig);
} catch (e) {
assert.strictEqual(e.errorNum, 12154);
assert.ok(e.stack.includes('asyncStack.js:67:'), e.stack);
} finally {
if (pool) {
await pool.close ();
await assert.rejects(
async () => await oracledb.createPool(config),
(e) => {
assert.ok(e.stack.includes('asyncStack.js:64:'), e.stack);
return true;
}
}
);
});
it('263.3 stack on error in execute', async () => {
const dbconfig = {
const config = {
user : process.env.NODE_ORACLEDB_USER,
password : process.env.NODE_ORACLEDB_PASSWORD,
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING
};
try {
const conn = await oracledb.getConnection(dbconfig);
await conn.execute("SELECT * FROM NON_EXISTENT_TABLE");
} catch (e) {
assert.strictEqual(e.errorNum, 942);
assert.ok(e.stack.includes('asyncStack.js:88:'), e.stack);
}
const conn = await oracledb.getConnection(config);
await assert.rejects(
async () => await conn.execute("SELECT * FROM NON_EXISTENT_TABLE"),
(e) => {
assert.ok(e.stack.includes('asyncStack.js:80:'), e.stack);
return true;
}
);
await conn.close();
});
});

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -35,7 +35,6 @@ const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('82.blobDMLBindAsBuffer.js', function() {
@ -107,45 +106,24 @@ describe('82.blobDMLBindAsBuffer.js', function() {
};
// compare the inserted blob with orginal content
let verifyBlobValueWithBuffer = async function(selectSql, originalBuffer, specialStr) {
let result = null;
result = await connection.execute(selectSql);
let lob = result.rows[0][0];
let verifyBlobValueWithBuffer = async function(selectSql, originalBuffer) {
const result = await connection.execute(selectSql);
const lob = result.rows[0][0];
if (originalBuffer == '' || originalBuffer == undefined) {
assert.ifError(lob);
assert.strictEqual(lob, null);
} else {
assert(lob);
let blobData = Buffer.alloc(0);
let totalLength = 0;
lob.on('data', function(chunk) {
totalLength = totalLength + chunk.length;
blobData = Buffer.concat([blobData, chunk], totalLength);
});
lob.on('error', function(err) {
assert(err, "lob.on 'error' event.");
});
lob.on('end', function() {
if (originalBuffer == "EMPTY_BLOB") {
let nullBuffer = Buffer.from('', "utf-8");
assert.strictEqual(assist.compare2Buffers(blobData, nullBuffer), true);
} else {
assert.strictEqual(totalLength, originalBuffer.length);
let specStrLength = specialStr.length;
assert.strictEqual(blobData.toString('utf8', 0, specStrLength), specialStr);
assert.strictEqual(blobData.toString('utf8', (totalLength - specStrLength), totalLength), specialStr);
assert.strictEqual(assist.compare2Buffers(blobData, originalBuffer), true);
}
});
const blobData = await lob.getData();
if (originalBuffer == "EMPTY_BLOB") {
assert.strictEqual(blobData, null);
} else {
assert.deepEqual(blobData, originalBuffer);
}
}
};
let checkInsertResult = async function(id, content, specialStr) {
let checkInsertResult = async function(id, content) {
let sql = "select blob from nodb_dml_blob_1 where id = " + id;
await verifyBlobValueWithBuffer(sql, content, specialStr);
await verifyBlobValueWithBuffer(sql, content);
};
describe('82.1 BLOB, INSERT', function() {
@ -297,7 +275,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
let content = Buffer.from(bigStr, "utf-8");
await insertIntoBlobTable1(id, content);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.11
it('82.1.12 works with Buffer length (64K - 1)', async function() {
@ -308,7 +286,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
let content = Buffer.from(bigStr, "utf-8");
await insertIntoBlobTable1(id, content);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.12
it('82.1.13 works with Buffer length (64K + 1)', async function() {
@ -319,7 +297,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
let content = Buffer.from(bigStr, "utf-8");
await insertIntoBlobTable1(id, content);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.13
it('82.1.14 works with Buffer length (1MB + 1)', async function() {
@ -330,7 +308,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
let content = Buffer.from(bigStr, "utf-8");
await insertIntoBlobTable1(id, content);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.14
it('82.1.15 bind value and type mismatch', async function() {
@ -364,7 +342,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
id, { val : content, dir : oracledb.BIND_IN, type : oracledb.BUFFER }
]);
assert.strictEqual(result.rowsAffected, 1);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.16
it('82.1.17 bind with invalid BLOB', async function() {
@ -399,7 +377,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
});
assert.strictEqual(result.rowsAffected, 1);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.18
it('82.1.19 works with bind in maxSize smaller than buffer size', async function() {
@ -418,7 +396,7 @@ describe('82.blobDMLBindAsBuffer.js', function() {
});
assert.strictEqual(result.rowsAffected, 1);
await checkInsertResult(id, content, specialStr);
await checkInsertResult(id, content);
}); // 82.1.19
}); // 82.1
@ -444,11 +422,11 @@ describe('82.blobDMLBindAsBuffer.js', function() {
await insertIntoBlobTable1(id, content_1);
await checkInsertResult(id, content_1, null);
await checkInsertResult(id, content_1);
await updateBlobTable1(id, content_2);
await checkInsertResult(id, content_2, specialStr_2);
await checkInsertResult(id, content_2);
}); // 82.2.1
it('82.2.2 update a cloumn with EMPTY_BLOB', async function() {
@ -461,11 +439,11 @@ describe('82.blobDMLBindAsBuffer.js', function() {
await insertIntoBlobTable1(id, content_1);
await checkInsertResult(id, content_1, specialStr_1);
await checkInsertResult(id, content_1);
await updateBlobTable1(id, content_2);
await checkInsertResult(id, content_2, null);
await checkInsertResult(id, content_2);
}); // 82.2.2
it('82.2.3 update EMPTY_BLOB column with empty buffer', async function() {
@ -493,11 +471,11 @@ describe('82.blobDMLBindAsBuffer.js', function() {
await insertIntoBlobTable1(id, content_1);
await checkInsertResult(id, content_1, null);
await checkInsertResult(id, content_1);
await updateBlobTable1(id, content_2);
await checkInsertResult(id, content_2, specialStr_2);
await checkInsertResult(id, content_2);
}); // 82.2.4
it('82.2.5 update a column with empty buffer', async function() {
@ -510,11 +488,11 @@ describe('82.blobDMLBindAsBuffer.js', function() {
await insertIntoBlobTable1(id, content_1);
await checkInsertResult(id, content_1, specialStr_1);
await checkInsertResult(id, content_1);
await updateBlobTable1(id, content_2);
await checkInsertResult(id, content_2, null);
await checkInsertResult(id, content_2);
}); // 82.2.5
}); // 82.2
});

View File

@ -37,9 +37,9 @@ const dbconfig = require('./dbconfig.js');
describe('161. changePassword.js', function() {
var DBA_config;
var dbaConn;
var sql;
let DBA_config;
let dbaConn;
let sql;
const myUser = dbconfig.user + "_cpw";
if (dbconfig.test.DBA_PRIVILEGE == true) {
DBA_config = {
@ -68,7 +68,6 @@ describe('161. changePassword.js', function() {
"END; ";
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
await dbaConn.execute(sql);
sql = "GRANT CREATE SESSION to " + myUser;
@ -80,22 +79,20 @@ describe('161. changePassword.js', function() {
if (dbconfig.test.DBA_PRIVILEGE) {
sql = "DROP USER " + myUser + " CASCADE";
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
await dbaConn.execute(sql);
await dbaConn.close();
}
}); // after
it('161.1 basic case', async function() {
var conn;
let conn;
const tpass = 'secret';
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
assert(conn);
// change password
await conn.changePassword(myUser, myUser, tpass);
await conn.close();
@ -107,7 +104,6 @@ describe('161. changePassword.js', function() {
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
assert(conn);
// restore password
await conn.changePassword(myUser, tpass, myUser);
@ -115,33 +111,28 @@ describe('161. changePassword.js', function() {
}); // 161.1
it('161.2 pooled connection', async function() {
var pool, conn;
let pool, conn;
const tpass = 'secret';
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
pool = await oracledb.createPool(credential);
assert(pool);
conn = await pool.getConnection();
assert(conn);
await conn.changePassword(myUser, myUser, tpass);
await conn.close();
// Still able to get connections
conn = await pool.getConnection();
assert(conn);
await conn.close();
await pool.close();
// verify with old password
pool = await oracledb.createPool(credential);
await assert.rejects(
async () => {
await pool.getConnection();
},
/ORA-01017/
);// ORA-01017: invalid username/password
async () => await pool.getConnection(),
/ORA-01017:/
);
await pool.close();
@ -153,30 +144,24 @@ describe('161. changePassword.js', function() {
};
pool = await oracledb.createPool(credential);
conn = await pool.getConnection();
assert(conn);
await conn.close();
await pool.close();
}); // 161.2
it('161.3 DBA changes password', async function() {
var dbaConn, conn;
const tpass = 'secret';
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
const dbaConn = await oracledb.getConnection(DBA_config);
await dbaConn.changePassword(myUser, '', tpass);
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-01017/
);// ORA-01017: invalid username/password
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
// verify with changed password
credential = {
@ -184,8 +169,7 @@ describe('161. changePassword.js', function() {
password: tpass,
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
assert(conn);
const conn = await oracledb.getConnection(credential);
await conn.close();
// restore password
@ -194,25 +178,21 @@ describe('161. changePassword.js', function() {
}); // 161.3
it('161.4 connects with an expired password', async function() {
var dbaConn, conn;
const tpass = 'secret';
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
const dbaConn = await oracledb.getConnection(DBA_config);
const sql = "alter user " + myUser + " password expire";
await dbaConn.execute(sql);
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-28001/
);// ORA-28001: the password has expired
async () => await oracledb.getConnection(credential),
/ORA-28001:/
);
credential = {
user: myUser,
@ -220,7 +200,7 @@ describe('161. changePassword.js', function() {
newPassword: tpass,
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
let conn = await oracledb.getConnection(credential);
await conn.close();
// restore password
@ -238,25 +218,21 @@ describe('161. changePassword.js', function() {
}); // 161.4
it('161.5 for DBA, the original password is ignored', async function() {
var dbaConn, conn;
const tpass = 'secret';
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
const dbaConn = await oracledb.getConnection(DBA_config);
await dbaConn.changePassword(myUser, 'foobar', tpass);
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-01017/
);// ORA-01017: invalid username/password
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
// verify with new password
credential = {
@ -265,8 +241,7 @@ describe('161. changePassword.js', function() {
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
assert(conn);
const conn = await oracledb.getConnection(credential);
await conn.close();
await dbaConn.changePassword(myUser, '', myUser);
await dbaConn.close();
@ -275,21 +250,18 @@ describe('161. changePassword.js', function() {
it('161.6 Negative: basic case, wrong original password', async function() {
const tpass = 'secret';
var credential = {
let credential = {
user: myUser,
password: myUser,
connectionString: dbconfig.connectString
};
const conn = await oracledb.getConnection(credential);
assert(conn);
const wrongOne = 'foobar';
await assert.rejects(
async () => {
await conn.changePassword(myUser, wrongOne, tpass);
},
/ORA-28008/
);// ORA-28008: invalid old password
async () => await conn.changePassword(myUser, wrongOne, tpass),
/ORA-28008:/
);
await conn.close();
@ -300,16 +272,13 @@ describe('161. changePassword.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-01017/
);// ORA-01017: invalid username/password
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
}); // 161.6
it.skip('161.7 Negative: basic case. invalid parameter', async function() {
var conn;
const tpass = 123;
const credential = {
user: myUser,
@ -317,13 +286,11 @@ describe('161. changePassword.js', function() {
connectionString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
const conn = await oracledb.getConnection(credential);
await assert.rejects(
async () => {
await conn.changePassword(myUser, myUser, tpass);
},
/NJS-005: invalid value for parameter 3/
async () => await conn.changePassword(myUser, myUser, tpass),
/NJS-005:/
);
await conn.close();
@ -331,29 +298,30 @@ describe('161. changePassword.js', function() {
it('161.8 Negative: non-DBA tries to change the password', async function() {
const tUser = dbconfig.user + "_st";
var dbaConn, tConn;
const tpass = 'secret';
dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
sql = "CREATE USER " + tUser + " IDENTIFIED BY " + tUser;
await dbaConn.execute(sql);
sql = "GRANT CREATE SESSION to " + tUser;
await dbaConn.execute(sql);
const dbaConn = await oracledb.getConnection(DBA_config);
try {
await dbaConn.execute(`drop user ${tUser} cascade`);
} catch (err) {
if (!err.message.startsWith('ORA-01918:'))
throw err;
}
var credential = {
await dbaConn.execute(`create user ${tUser} identified by ${tUser}`);
await dbaConn.execute(`grant create session to ${tUser}`);
let credential = {
user: tUser,
password: tUser,
connectionString: dbconfig.connectString
};
tConn = await oracledb.getConnection(credential);
const tConn = await oracledb.getConnection(credential);
await assert.rejects(
async () => {
await tConn.changePassword(myUser, myUser, tpass);
},
/ORA-01031/
async () => await tConn.changePassword(myUser, myUser, tpass),
/ORA-01031:/
);
credential = {
@ -363,15 +331,12 @@ describe('161. changePassword.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-01017/
);// ORA-01017: invalid username/password
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
await tConn.close();
sql = "DROP USER " + tUser + " CASCADE";
await dbaConn.execute(sql);
await dbaConn.execute(`drop user ${tUser} cascade`);
await dbaConn.close();
}); // 161.8
@ -383,22 +348,17 @@ describe('161. changePassword.js', function() {
newPassword: wrongOne,
connectionString: dbconfig.connectString
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/NJS-007: invalid value for "newPassword" in parameter 1/
async () => await oracledb.getConnection(credential),
/NJS-007:/
);
}); // 161.9
it('161.10 sets "newPassword" to be an empty string. password unchanged', async function() {
const dbaConn = await oracledb.getConnection(DBA_config);
assert(dbaConn);
sql = "alter user " + myUser + " password expire";
await dbaConn.execute(sql);
await dbaConn.execute(`alter user ${myUser} password expire`);
var credential = {
let credential = {
user: myUser,
password: myUser,
newPassword: '',
@ -406,11 +366,9 @@ describe('161. changePassword.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-28001/
);// ORA-28001: the password has expired
async () => await oracledb.getConnection(credential),
/ORA-28001:/
);
credential = {
user: myUser,
@ -419,11 +377,9 @@ describe('161. changePassword.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-28001/
);// ORA-28001: the password has expired
async () => await oracledb.getConnection(credential),
/ORA-28001:/
);
}); // 161.10
});

View File

@ -111,9 +111,7 @@ describe('1. connection.js', function() {
it('1.1.4 Negative test - invalid outFormat value', async function() {
await assert.rejects(
async () => {
await connection.execute(query, {id: 20}, {outFormat:0 });
},
async () => await connection.execute(query, {id: 20}, {outFormat:0 }),
/NJS-007:/
);
});
@ -334,9 +332,7 @@ describe('1. connection.js', function() {
privilege: null
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/NJS-007: invalid value for "privilege" in parameter 1/
);
});
@ -349,10 +345,8 @@ describe('1. connection.js', function() {
privilege: 'sysdba'
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/NJS-007: invalid value for "privilege" in parameter 1/
async () => await oracledb.getConnection(credential),
/NJS-007:/
);
});
@ -365,10 +359,8 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/ORA-24300/
async () => await oracledb.getConnection(credential),
/ORA-24300:/
);// ORA-24300: bad value for mode
});
@ -381,10 +373,8 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
/NJS-007: invalid value for "privilege" in parameter 1/
async () => await oracledb.getConnection(credential),
/NJS-007:/
);
});
@ -416,10 +406,8 @@ describe('1. connection.js', function() {
const conn = await oracledb.getConnection(dbConfig);
await conn.close();
await assert.rejects(
async () => {
await conn.ping();
},
/NJS-003: invalid connection/
async () => await conn.ping(),
/NJS-003:/
);
});
}); // 1.8
@ -435,9 +423,7 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/NJS-075:/
);
});
@ -454,9 +440,7 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/NJS-080:/
);
});
@ -483,6 +467,7 @@ describe('1. connection.js', function() {
await oracledb.getConnection(credential);
});
}); //1.10
describe('1.11 Invalid credentials', function() {
it('1.11.1 using bad connect string', async function() {
@ -493,9 +478,7 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/ORA-12154:/
);
});
@ -508,9 +491,7 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
});
@ -523,9 +504,7 @@ describe('1. connection.js', function() {
};
await assert.rejects(
async () => {
await oracledb.getConnection(credential);
},
async () => await oracledb.getConnection(credential),
/ORA-01017:/
);
});
@ -543,9 +522,7 @@ describe('1. connection.js', function() {
connection = await oracledb.getConnection(credential);
await connection.close();
await assert.rejects(
async () => {
await connection.execute('SELECT * FROM DUAL');
},
async () => await connection.execute('SELECT * FROM DUAL'),
/NJS-003:/
);
});

View File

@ -32,7 +32,6 @@
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
const random = require('./random.js');
@ -59,37 +58,31 @@ describe('103. dataTypeLong.js', function() {
for (let i = 0; i < strLen.length; i++)
strs[i] = random.getRandomString(strLen[i], specialStr);
before(function(done) {
assist.setUp(connection, tableName, strs, done);
before(async function() {
await assist.setUp(connection, tableName, strs);
});
after(function(done) {
connection.execute(
"drop table " + tableName + " purge",
function(err) {
assert.ifError(err);
done();
}
);
after(async function() {
await connection.execute("drop table " + tableName + " purge");
});
it('103.1.1 SELECT query', function(done) {
assist.dataTypeSupport(connection, tableName, strs, done);
it('103.1.1 SELECT query', async function() {
await assist.dataTypeSupport(connection, tableName, strs);
});
it('103.1.2 works well with result set', function(done) {
assist.verifyResultSet(connection, tableName, strs, done);
it('103.1.2 works well with result set', async function() {
await assist.verifyResultSet(connection, tableName, strs);
});
it('103.1.3 works well with REF Cursor', function(done) {
assist.verifyRefCursor(connection, tableName, strs, done);
it('103.1.3 works well with REF Cursor', async function() {
await assist.verifyRefCursor(connection, tableName, strs);
});
}); // 103.1
describe('103.2 stores null values correctly', function() {
it('103.2.1 testing Null, Empty string and Undefined', function(done) {
assist.verifyNullValues(connection, tableName, done);
it('103.2.1 testing Null, Empty string and Undefined', async function() {
await assist.verifyNullValues(connection, tableName);
});
});
});

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2019, 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -32,7 +32,7 @@
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const assert = require('assert');
const fs = require('fs');
const util = require('util');
const dbconfig = require('./dbconfig.js');
@ -45,203 +45,167 @@ describe('196. getDataOfLob.js', () => {
const tab2 = 'nodb_tab_myblob';
before('prepare the table', async () => {
try {
conn = await oracledb.getConnection(dbconfig);
conn = await oracledb.getConnection(dbconfig);
let sql =
`create table ${tab1} (
id number(9) not null,
value clob not null
)`;
let plsql = testsUtil.sqlCreateTable(tab1, sql);
await conn.execute(plsql);
let sql =
`create table ${tab1} (
id number(9) not null,
value clob not null
)`;
let plsql = testsUtil.sqlCreateTable(tab1, sql);
await conn.execute(plsql);
sql =
`create table ${tab2} (
id number(9) not null,
value blob not null
)`;
plsql = testsUtil.sqlCreateTable(tab2, sql);
await conn.execute(plsql);
} catch (err) {
should.not.exist(err);
}
sql =
`create table ${tab2} (
id number(9) not null,
value blob not null
)`;
plsql = testsUtil.sqlCreateTable(tab2, sql);
await conn.execute(plsql);
}); // before()
after(async () => {
try {
let sql = `drop table ${tab1} purge`;
await conn.execute(sql);
let sql = `drop table ${tab1} purge`;
await conn.execute(sql);
sql = `drop table ${tab2} purge`;
await conn.execute(sql);
sql = `drop table ${tab2} purge`;
await conn.execute(sql);
await conn.close();
} catch (err) {
should.not.exist(err);
}
await conn.close();
}); // after()
it('196.1 getData() works on CLOB ', async () => {
try {
let content = 'A short string value';
let sql = `insert into ${tab1} values (1, '${content}')`;
await conn.execute(sql);
let content = 'A short string value';
let sql = `insert into ${tab1} values (1, '${content}')`;
await conn.execute(sql);
sql = `select * from ${tab1} where id = 1`;
const result = await conn.execute(sql);
const clob = result.rows[0][1];
const value = await clob.getData();
sql = `select * from ${tab1} where id = 1`;
const result = await conn.execute(sql);
const clob = result.rows[0][1];
const value = await clob.getData();
should.strictEqual(value, content);
} catch (err) {
should.not.exist(err);
}
assert.strictEqual(value, content);
}); // 196.1
it('196.2 getData() returns CLOB as Strings', async () => {
try {
const txtFile = 'test/clobexample.txt';
const inStream = fs.createReadStream(txtFile);
const num = 2;
let sql = `insert into ${tab1} values (:i, empty_clob())
returning value into :lobbv`;
let binds = { i: num, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } };
let opt = { autoCommit: false };
const txtFile = 'test/clobexample.txt';
const inStream = fs.createReadStream(txtFile);
const num = 2;
let sql = `insert into ${tab1} values (:i, empty_clob())
returning value into :lobbv`;
let binds = { i: num, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } };
let opt = { autoCommit: false };
// Insertion with Stream
const result = await conn.execute(sql, binds, opt);
// Insertion with Stream
const result = await conn.execute(sql, binds, opt);
const clob = result.outBinds.lobbv[0];
inStream.pipe(clob);
const clob = result.outBinds.lobbv[0];
inStream.pipe(clob);
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
clob.on('error', reject);
clob.on('finish', () => resolve(conn.commit()));
});
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
clob.on('error', reject);
clob.on('finish', () => resolve(conn.commit()));
});
await insertionComplete;
await insertionComplete;
// Query
sql = `select value from ${tab1} where id = ${num}`;
const outResult = await conn.execute(sql);
const outLob = outResult.rows[0][0];
// Query
sql = `select value from ${tab1} where id = ${num}`;
const outResult = await conn.execute(sql);
const outLob = outResult.rows[0][0];
const queryResult = await outLob.getData();
const queryResult = await outLob.getData();
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(txtFile);
should.strictEqual(queryResult, content.toString());
} catch (err) {
should.not.exist(err);
}
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(txtFile);
assert.strictEqual(queryResult, content.toString());
}); // 196.2
it('196.3 getData() on BLOB', async () => {
try {
let content = 'A somewhat longer BLOB value';
let sql = `insert into ${tab2} values ( 1, utl_raw.cast_to_raw('${content}') )`;
await conn.execute(sql);
const content = 'A somewhat longer BLOB value';
let sql = `insert into ${tab2} values ( 1, utl_raw.cast_to_raw('${content}') )`;
await conn.execute(sql);
sql = `select * from ${tab2} where id = 1`;
const result = await conn.execute(sql);
const clob = result.rows[0][1];
const value = await clob.getData();
sql = `select * from ${tab2} where id = 1`;
const result = await conn.execute(sql);
const clob = result.rows[0][1];
const value = await clob.getData();
should.strictEqual(value.toString(), content);
} catch (err) {
should.not.exist(err);
}
assert.strictEqual(value.toString(), content);
}); // 196.3
it('196.4 getData() returns BLOB as Buffer', async () => {
try {
const jpgFile = 'test/tree.jpg';
const inStream = fs.createReadStream(jpgFile);
const num = 2;
let sql = `insert into ${tab2} values (:i, empty_blob())
returning value into :lobbv`;
let binds = { i: num, lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } };
let opt = { autoCommit: false };
const jpgFile = 'test/tree.jpg';
const inStream = fs.createReadStream(jpgFile);
const num = 2;
let sql = `insert into ${tab2} values (:i, empty_blob())
returning value into :lobbv`;
let binds = { i: num, lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } };
let opt = { autoCommit: false };
// Insertion with Stream
const result = await conn.execute(sql, binds, opt);
// Insertion with Stream
const result = await conn.execute(sql, binds, opt);
const blob = result.outBinds.lobbv[0];
inStream.pipe(blob);
const blob = result.outBinds.lobbv[0];
inStream.pipe(blob);
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
blob.on('error', reject);
blob.on('finish', () => resolve(conn.commit()));
});
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
blob.on('error', reject);
blob.on('finish', () => resolve(conn.commit()));
});
await insertionComplete;
await insertionComplete;
// Query
sql = `select value from ${tab2} where id = ${num}`;
const outResult = await conn.execute(sql);
const outLob = outResult.rows[0][0];
// Query
sql = `select value from ${tab2} where id = ${num}`;
const outResult = await conn.execute(sql);
const outLob = outResult.rows[0][0];
const queryResult = await outLob.getData();
const queryResult = await outLob.getData();
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(jpgFile);
let isEqual = content.equals(queryResult);
(isEqual).should.be.true();
} catch (err) {
should.not.exist(err);
}
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(jpgFile);
const isEqual = content.equals(queryResult);
assert.strictEqual(isEqual, true);
}); // 196.4
it('196.5 getData() on empty LOB returns null', async () => {
try {
const tempLob = await conn.createLob(oracledb.BLOB);
const value = await tempLob.getData();
should.strictEqual(value, null);
await tempLob.close();
} catch (err) {
should.not.exist(err);
}
const tempLob = await conn.createLob(oracledb.BLOB);
const value = await tempLob.getData();
assert.strictEqual(value, null);
await tempLob.close();
}); // 196.5
it('196.6 works with temp LOB', async () => {
try {
const inFileName = 'test/clobexample.txt';
const tempLob = await conn.createLob(oracledb.CLOB);
const inStream = fs.createReadStream(inFileName);
const inFileName = 'test/clobexample.txt';
const tempLob = await conn.createLob(oracledb.CLOB);
const inStream = fs.createReadStream(inFileName);
inStream.pipe(tempLob);
inStream.pipe(tempLob);
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
tempLob.on('error', reject);
tempLob.on('finish', resolve);
});
let insertionComplete = new Promise((resolve, reject) => {
inStream.on('error', reject);
tempLob.on('error', reject);
tempLob.on('finish', resolve);
});
await insertionComplete;
await insertionComplete;
// Query
const queryResult = await tempLob.getData();
// Query
const queryResult = await tempLob.getData();
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(inFileName);
should.strictEqual(queryResult, content.toString());
// Verify
const readFile = util.promisify(fs.readFile);
const content = await readFile(inFileName);
assert.strictEqual(queryResult, content.toString());
await tempLob.close();
} catch (err) {
should.not.exist(err);
}
await tempLob.close();
}); // 196.6
});

View File

@ -372,6 +372,7 @@ describe('43. plsqlBindIndexedTable1.js', function() {
before(async function() {
connection = await oracledb.getConnection(dbConfig);
await connection.execute("alter session set time_zone = 'UTC'");
});
after(async function() {
@ -440,7 +441,8 @@ describe('43. plsqlBindIndexedTable1.js', function() {
const result = await connection.execute(sql, bindvars);
assert.strictEqual(result.outBinds.stringValue, 'Space odyssey');
assert.strictEqual(result.outBinds.numberValue, 2001);
assert.deepEqual(result.outBinds.dateValue, new Date(1968, 3, 2));
assert.deepEqual(result.outBinds.dateValue,
new Date(Date.UTC(1968, 3, 2)));
await connection.execute("DROP PROCEDURE nodb_plsqlbindproc33");
});
@ -463,7 +465,7 @@ describe('43. plsqlBindIndexedTable1.js', function() {
const result = await connection.execute(sql, bindvars);
assert.strictEqual(result.outBinds[0], 'Space odyssey');
assert.strictEqual(result.outBinds[1], 2001);
assert.deepEqual(result.outBinds[2], new Date(1968, 3, 2));
assert.deepEqual(result.outBinds[2], new Date(Date.UTC(1968, 3, 2)));
await connection.execute("DROP PROCEDURE nodb_plsqlbindproc34");
});