Skip to content

Commit e4a84b5

Browse files
committed
Add the test suite
1 parent b97480b commit e4a84b5

35 files changed

+7319
-0
lines changed

test/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Testing node-oracledb
2+
3+
*Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*
4+
5+
You may not use the identified files except in compliance with the Apache
6+
License, Version 2.0 (the "License.")
7+
8+
You may obtain a copy of the License at
9+
http://www.apache.org/licenses/LICENSE-2.0.
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
## Running the complete test suite
19+
20+
### 1. Create a working directory
21+
22+
```
23+
mkdir <some-directory>
24+
cd <some-directory>
25+
```
26+
27+
### 2. Install node-oracledb
28+
29+
See [INSTALL](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md)
30+
31+
Install with:
32+
33+
```
34+
npm install oracledb
35+
```
36+
37+
Alternatively use a GitHub clone:
38+
39+
```
40+
git clone https://github.com/oracle/node-oracledb.git
41+
npm install node-oracledb
42+
```
43+
44+
### 3. Install dependent modules
45+
46+
The test suite uses [mocha](https://www.npmjs.com/package/mocha), [async](https://www.npmjs.com/package/async) and [should](https://www.npmjs.com/package/should). These need to be installed separately.
47+
48+
```
49+
cd <some-directory>/node_modules/oracledb
50+
npm install mocha should async
51+
```
52+
53+
Note: these are listed in `devDependencies` and `package.json` so `npm
54+
install` will install them when executed inside a node-oracledb
55+
package directory.
56+
57+
### 4. Edit database credentials
58+
59+
```
60+
vi <some-directory>/node_modules/oracledb/test/dbConfig.js
61+
```
62+
63+
The user requires privileges to connect and create tables.
64+
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.
66+
67+
### 5. Run test suite
68+
69+
All tests can be run with:
70+
71+
```
72+
cd <some-directory>/node_modules/oracledb
73+
npm test
74+
```
75+
76+
This calls the `test` script defined in `<some-directory>/node_modules/oracledb/package.json`.
77+
If `mocha` is not in the directory specified in `package.json`, for example if you have installed it globally, then edit `package.json` and change the path.
78+
79+
## Running a single test
80+
81+
Individual tests can be run using:
82+
83+
```
84+
cd <some-directory>/node_modules/oracledb
85+
../mocha/bin/mocha test/<test-name>
86+
```
87+
88+
See [mochajs.org](http://mochajs.org/) for more information on running tests with mocha.
89+
90+
## Adding Tests
91+
See [CONTRIBUTING](https://github.com/oracle/node-oracledb/blob/master/CONTRIBUTING.md) for general information on contribution requirements.
92+
93+
For easy correlation between results and test code, each test is
94+
assigned a number. The following number ranges have been chosen:
95+
96+
- 1 - 20 are reserved for basic functional tests
97+
- 21 - 50 are reserved for data type supporting tests
98+
- 51 onwards are for other tests
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 51. accessTerminatedPoolAttributes.js
23+
*
24+
* DESCRIPTION
25+
* Testing driver's behaviour when access attributes of terminated pool.
26+
*
27+
* NUMBERING RULE
28+
* Test numbers follow this numbering rule:
29+
* 1 - 20 are reserved for basic functional tests
30+
* 21 - 50 are reserved for data type supporting tests
31+
* 51 - are for other tests
32+
*
33+
*****************************************************************************/
34+
35+
var oracledb = require('oracledb');
36+
var should = require('should');
37+
var dbConfig = require('./dbConfig.js');
38+
39+
describe('51. accessTerminatedPoolAttributes.js', function(){
40+
41+
if(dbConfig.externalAuth){
42+
var credential = { externalAuth: true, connectString: dbConfig.connectString };
43+
} else {
44+
var credential = dbConfig;
45+
}
46+
47+
it('can not access attributes of terminated pool', function(done){
48+
oracledb.createPool(
49+
{
50+
externalAuth : credential.externalAuth,
51+
user : credential.user,
52+
password : credential.password,
53+
connectString : credential.connectString,
54+
poolMin : 2,
55+
poolMax : 10
56+
},
57+
function(err, pool){
58+
should.not.exist(err);
59+
pool.should.be.ok;
60+
if(credential.externalAuth){
61+
pool.connectionsOpen.should.be.exactly(0);
62+
} else {
63+
pool.connectionsOpen.should.be.exactly(pool.poolMin);
64+
}
65+
//(pool.connectionsOpen).should.eql(2);
66+
(pool.connectionsInUse).should.eql(0);
67+
68+
pool.getConnection( function(err, connection){
69+
(pool.connectionsInUse).should.eql(1);
70+
71+
connection.release( function(err){
72+
should.not.exist(err);
73+
(pool.connectionsInUse).should.eql(0);
74+
75+
pool.terminate( function(err){
76+
should.not.exist(err);
77+
try{
78+
(pool.connectionsOpen).should.eql(2);
79+
}
80+
catch(err){
81+
should.exist(err);
82+
(err.message).should.eql('NJS-002: invalid pool');
83+
}
84+
done();
85+
});
86+
});
87+
});
88+
}
89+
);
90+
91+
})
92+
})

test/autoCommit.js

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 7. autoCommit.js
23+
*
24+
* DESCRIPTION
25+
* Testing general autoCommit feature.
26+
*
27+
* NUMBERING RULE
28+
* Test numbers follow this numbering rule:
29+
* 1 - 20 are reserved for basic functional tests
30+
* 21 - 50 are reserved for data type supporting tests
31+
* 51 - are for other tests
32+
*
33+
*****************************************************************************/
34+
35+
var oracledb = require('oracledb');
36+
var should = require('should');
37+
var async = require('async');
38+
var dbConfig = require('./dbConfig.js');
39+
40+
describe('7. autoCommit.js', function(){
41+
42+
if(dbConfig.externalAuth){
43+
var credential = { externalAuth: true, connectString: dbConfig.connectString };
44+
} else {
45+
var credential = dbConfig;
46+
}
47+
48+
var connection = false;
49+
var anotherConnection = false;
50+
var script =
51+
"BEGIN \
52+
DECLARE \
53+
e_table_exists EXCEPTION; \
54+
PRAGMA EXCEPTION_INIT(e_table_exists, -00942); \
55+
BEGIN \
56+
EXECUTE IMMEDIATE ('DROP TABLE oracledb_departments'); \
57+
EXCEPTION \
58+
WHEN e_table_exists \
59+
THEN NULL; \
60+
END; \
61+
EXECUTE IMMEDIATE (' \
62+
CREATE TABLE oracledb_departments ( \
63+
department_id NUMBER, \
64+
department_name VARCHAR2(20) \
65+
) \
66+
'); \
67+
END; ";
68+
69+
beforeEach(function(done){
70+
oracledb.outFormat = oracledb.OBJECT;
71+
oracledb.autoCommit = true;
72+
73+
async.series([
74+
function(callback){
75+
oracledb.getConnection(credential, function(err, conn){
76+
if(err) { console.error(err.message); return; }
77+
connection = conn;
78+
callback();
79+
});
80+
},
81+
function(callback){
82+
oracledb.getConnection(credential, function(err, conn){
83+
if(err) { console.error(err.message); return; }
84+
anotherConnection = conn;
85+
callback();
86+
});
87+
},
88+
function(callback){
89+
connection.execute(script, function(err){
90+
if(err) { console.error(err.message); return; }
91+
connection.commit( function(err){
92+
if(err) { console.error(err.message); return; }
93+
callback();
94+
});
95+
});
96+
}
97+
], done);
98+
99+
100+
})
101+
102+
afterEach(function(done){
103+
oracledb.outFormat = oracledb.ARRAY;
104+
oracledb.autoCommit = false;
105+
106+
async.series([
107+
function(callback){
108+
connection.execute(
109+
'DROP TABLE oracledb_departments',
110+
function(err){
111+
if(err) { console.error(err.message); return; }
112+
callback();
113+
}
114+
);
115+
},
116+
function(callback){
117+
connection.release( function(err){
118+
if(err) { console.error(err.message); return; }
119+
callback();
120+
});
121+
},
122+
function(callback){
123+
anotherConnection.release( function(err){
124+
if(err) { console.error(err.message); return; }
125+
callback();
126+
});
127+
}
128+
], done);
129+
})
130+
131+
it('7.1 auto commit takes effect for DML - insert', function(done){
132+
async.series([
133+
function(callback){
134+
connection.execute(
135+
"INSERT INTO oracledb_departments VALUES (82, 'Security')",
136+
function(err){
137+
should.not.exist(err);
138+
callback();
139+
}
140+
);
141+
},
142+
function(callback){
143+
anotherConnection.execute(
144+
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
145+
function(err, result){
146+
should.not.exist(err);
147+
should.exist(result);
148+
// console.log(result);
149+
result.rows[0].DEPARTMENT_ID.should.eql(82).and.be.a.Number;
150+
callback();
151+
}
152+
);
153+
}
154+
], done);
155+
})
156+
157+
it('7.2 auto commit takes effect for DML - update', function(done){
158+
async.series([
159+
function(callback){
160+
connection.execute(
161+
"INSERT INTO oracledb_departments VALUES (82, 'Security')",
162+
function(err){
163+
should.not.exist(err);
164+
callback();
165+
}
166+
);
167+
},
168+
function(callback){
169+
connection.execute(
170+
"UPDATE oracledb_departments SET department_id = 101 WHERE department_name = 'Security'",
171+
function(err){
172+
should.not.exist(err);
173+
callback();
174+
}
175+
);
176+
},
177+
function(callback){
178+
anotherConnection.execute(
179+
"SELECT department_id FROM oracledb_departments WHERE department_name = 'Security'",
180+
function(err, result){
181+
should.not.exist(err);
182+
should.exist(result);
183+
// console.log(result);
184+
result.rows[0].DEPARTMENT_ID.should.eql(101).and.be.a.Number;
185+
callback();
186+
}
187+
);
188+
}
189+
], done);
190+
})
191+
})

0 commit comments

Comments
 (0)