Skip to content

Commit 12041c4

Browse files
committed
Tidy up tests
1 parent 4124974 commit 12041c4

25 files changed

+2600
-1487
lines changed

test/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717

18+
The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
See LICENSE.md for relevant licenses.
20+
1821
## Running the complete test suite
1922

2023
### 1. Create a working directory
@@ -27,6 +30,7 @@ cd <some-directory>
2730
### 2. Install node-oracledb
2831

2932
See [INSTALL](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md)
33+
for installation requirements and more details.
3034

3135
Install with:
3236

@@ -50,7 +54,7 @@ cd <some-directory>/node_modules/oracledb
5054
npm install mocha should async
5155
```
5256

53-
Note: these are listed in `devDependencies` and `package.json` so `npm
57+
Note: these are listed in `devDependencies` in `package.json` so `npm
5458
install` will install them when executed inside a node-oracledb
5559
package directory.
5660

@@ -60,9 +64,22 @@ package directory.
6064
vi <some-directory>/node_modules/oracledb/test/dbConfig.js
6165
```
6266

63-
The user requires privileges to connect and create tables.
67+
Change the credentials to a user who has privileges to connect and create tables:
68+
69+
```javascript
70+
module.exports = {
71+
user : "hr",
72+
password : "welcome",
73+
connectString : "localhost/orcl",
74+
externalAuth : false
75+
};
76+
```
6477

65-
If you use external authentication, make sure Oracle Database and the authentication service have been appropriately configured. Also set the `externalAuth` property to `true` in `test/dbConfig.js`. See [Documentation for External Authentication](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth) for more details.
78+
To use external authentication, set the `externalAuth` property to
79+
`true`. Also make sure Oracle Database and the authentication service
80+
have been appropriately configured. See
81+
[Documentation for External Authentication](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth)
82+
for more details.
6683

6784
### 5. Run test suite
6885

test/binding.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('4. binding.js', function() {
308308
var proc = "CREATE OR REPLACE PROCEDURE oracledb_testproc (p_out OUT VARCHAR2) \
309309
AS \
310310
BEGIN \
311-
p_out := 'ABCDEF'; \
311+
p_out := 'ABCDEF GHIJK LMNOP QRSTU'; \
312312
END;";
313313
connection.should.be.ok;
314314
connection.execute(
@@ -328,7 +328,7 @@ describe('4. binding.js', function() {
328328
function(err, result) {
329329
should.exist(err);
330330
// console.log(err.message);
331-
err.message.should.startWith('ORA-06502: PL/SQL: numeric or value error: character string buffer too small');
331+
err.message.should.startWith('ORA-06502:');
332332
// console.log(result);
333333
callback();
334334
}
@@ -343,7 +343,7 @@ describe('4. binding.js', function() {
343343
function(err, result) {
344344
should.exist(err);
345345
// console.log(err.message);
346-
err.message.should.startWith('ORA-06502: PL/SQL: numeric or value error: character string buffer too small');
346+
err.message.should.startWith('ORA-06502:');
347347
// console.log(result);
348348
callback();
349349
}

test/dataTypeAssist.js

Lines changed: 166 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
1821
* NAME
1922
* 21. datatypeAssist.js
2023
*
@@ -28,7 +31,11 @@
2831
* 51 - are for other tests
2932
*
3033
*****************************************************************************/
31-
34+
35+
var oracledb = require('oracledb');
36+
var should = require('should');
37+
var async = require('async');
38+
3239
var assist = exports;
3340
assist.data = {
3441
specialChars: [
@@ -93,16 +100,16 @@ assist.data = {
93100
],
94101
alphabet: [
95102
'A', 'B', 'C', 'D', 'E',
96-
'F', 'G', 'H', 'I', 'J',
97-
'K', 'L', 'M', 'N', 'O',
98-
'P', 'Q', 'R', 'S', 'T',
99-
'U', 'V', 'W', 'X', 'Y',
100-
'Z', 'a', 'b', 'c', 'd',
101-
'e', 'f', 'g', 'h', 'i',
102-
'j', 'k', 'l', 'm', 'n',
103-
'o', 'p', 'q', 'r', 's',
104-
't', 'u', 'v', 'w', 'x',
105-
'y', 'z'
103+
'F', 'G', 'H', 'I', 'J',
104+
'K', 'L', 'M', 'N', 'O',
105+
'P', 'Q', 'R', 'S', 'T',
106+
'U', 'V', 'W', 'X', 'Y',
107+
'Z', 'a', 'b', 'c', 'd',
108+
'e', 'f', 'g', 'h', 'i',
109+
'j', 'k', 'l', 'm', 'n',
110+
'o', 'p', 'q', 'r', 's',
111+
't', 'u', 'v', 'w', 'x',
112+
'y', 'z'
106113
]
107114
};
108115

@@ -113,14 +120,14 @@ var StringBuffer = function() {
113120

114121
StringBuffer.prototype = {
115122
append: function(s) {
116-
this.buffer[this.index] = s;
117-
this.index += 1;
118-
return this;
119-
},
120-
121-
toString: function() {
122-
return this.buffer.join("");
123-
}
123+
this.buffer[this.index] = s;
124+
this.index += 1;
125+
return this;
126+
},
127+
128+
toString: function() {
129+
return this.buffer.join("");
130+
}
124131
};
125132

126133
assist.createCharString = function(size) {
@@ -130,13 +137,146 @@ assist.createCharString = function(size) {
130137
var cIndex = 0;
131138
for(var i = 0; i < size; i++) {
132139
if(i % 10 == 0) {
133-
buffer.append(assist.data.specialChars[scIndex]);
134-
scIndex = (scIndex + 1) % scSize;
135-
} else {
136-
cIndex = Math.floor(Math.random() * 52); // generate a random integer among 0-51
137-
buffer.append(assist.data.alphabet[cIndex]);
138-
}
140+
buffer.append(assist.data.specialChars[scIndex]);
141+
scIndex = (scIndex + 1) % scSize;
142+
} else {
143+
cIndex = Math.floor(Math.random() * 52); // generate a random integer among 0-51
144+
buffer.append(assist.data.alphabet[cIndex]);
145+
}
139146
}
140147
return buffer.toString();
141148
}
142-
module.exports = assist;
149+
150+
assist.setup = function(connection, tableName, sqlCreate, array, done) {
151+
async.series([
152+
function(callback) {
153+
connection.execute(
154+
sqlCreate,
155+
function(err) {
156+
should.not.exist(err);
157+
callback();
158+
}
159+
);
160+
},
161+
function(callback) {
162+
async.forEach(array, function(element, cb) {
163+
connection.execute(
164+
"INSERT INTO " + tableName + " VALUES(:no, :bindValue)",
165+
{ no: array.indexOf(element), bindValue: element },
166+
function(err) {
167+
should.not.exist(err);
168+
cb();
169+
}
170+
);
171+
}, function(err) {
172+
should.not.exist(err);
173+
callback();
174+
});
175+
}
176+
], done);
177+
}
178+
179+
assist.dataTypeSupport = function(connection, tableName, array, done) {
180+
connection.should.be.ok;
181+
connection.execute(
182+
"SELECT * FROM " + tableName,
183+
[],
184+
{ outFormat: oracledb.OBJECT },
185+
function(err, result) {
186+
should.not.exist(err);
187+
// console.log(result);
188+
for(var i = 0; i < array.length; i++) {
189+
if( (typeof result.rows[i].CONTENT) === 'string' )
190+
result.rows[i].CONTENT.trim().should.eql(array[result.rows[i].NUM]);
191+
else if( (typeof result.rows[i].CONTENT) === 'number' )
192+
result.rows[i].CONTENT.should.eql(array[result.rows[i].NUM]);
193+
else
194+
result.rows[i].CONTENT.toUTCString().should.eql(array[result.rows[i].NUM].toUTCString());
195+
}
196+
done();
197+
}
198+
);
199+
}
200+
201+
assist.resultSetSupport = function(connection, tableName, array, done) {
202+
connection.should.be.ok;
203+
var numRows = 3; // number of rows to return from each call to getRows()
204+
connection.execute(
205+
"SELECT * FROM " + tableName,
206+
[],
207+
{ resultSet: true, outFormat: oracledb.OBJECT },
208+
function(err, result) {
209+
should.not.exist(err);
210+
(result.resultSet.metaData[0]).name.should.eql('NUM');
211+
(result.resultSet.metaData[1]).name.should.eql('CONTENT');
212+
fetchRowsFromRS(result.resultSet);
213+
}
214+
);
215+
216+
function fetchRowsFromRS(rs) {
217+
rs.getRows(numRows, function(err, rows) {
218+
should.not.exist(err);
219+
if(rows.length > 0) {
220+
for(var i = 0; i < rows.length; i++) {
221+
if( (typeof rows[i].CONTENT) === 'string' )
222+
rows[i].CONTENT.trim().should.eql(array[rows[i].NUM]);
223+
else if( (typeof rows[i].CONTENT) === 'number' )
224+
rows[i].CONTENT.should.eql(array[rows[i].NUM]);
225+
else
226+
rows[i].CONTENT.toUTCString().should.eql(array[rows[i].NUM].toUTCString());
227+
}
228+
return fetchRowsFromRS(rs);
229+
} else if(rows.length == 0) {
230+
rs.close(function(err) {
231+
should.not.exist(err);
232+
done();
233+
});
234+
} else {
235+
var lengthLessThanZero = true;
236+
should.not.exist(lengthLessThanZero);
237+
done();
238+
}
239+
});
240+
}
241+
}
242+
243+
assist.nullValueSupport = function(connection, tableName, done) {
244+
connection.should.be.ok;
245+
var sqlInsert = "INSERT INTO " + tableName + " VALUES(:no, :bindValue)";
246+
async.series([
247+
function(callback) {
248+
connection.execute(
249+
sqlInsert,
250+
{ no: 998, bindValue: '' },
251+
function(err) {
252+
should.not.exist(err);
253+
callback();
254+
}
255+
);
256+
},
257+
function(callback) {
258+
connection.execute(
259+
sqlInsert,
260+
{ no: 999, bindValue: null },
261+
function(err) {
262+
should.not.exist(err);
263+
callback();
264+
}
265+
);
266+
},
267+
function(callback) {
268+
connection.execute(
269+
"SELECT * FROM " + tableName + " WHERE num > :1 ORDER BY num",
270+
[990],
271+
function(err, result) {
272+
should.not.exist(err);
273+
// console.log(result);
274+
result.rows.should.eql([ [998, null], [999, null] ]);
275+
callback();
276+
}
277+
);
278+
}
279+
], done);
280+
}
281+
282+
module.exports = assist;

0 commit comments

Comments
 (0)