mirror of
https://github.com/netfun2000/ip2region.git
synced 2026-02-27 09:44:31 +08:00
[Feature] Add 'memorySearch' and 'memorySearchSync' for Nodejs
1) Add features. 2) Add unit tests. 3) Add benchmark.
This commit is contained in:
28
binding/nodejs/tests/unitTests/exceptionTest.spec.js
Normal file
28
binding/nodejs/tests/unitTests/exceptionTest.spec.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// This test is used for tesing of exceptions
|
||||
|
||||
const IP2Region = require('../../ip2region');
|
||||
|
||||
describe('Constructor Test', () => {
|
||||
let instance;
|
||||
|
||||
beforeAll(() => {
|
||||
instance = new IP2Region({ dbPath: '../../data/ip2region.db' })
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
instance.destroy();
|
||||
});
|
||||
|
||||
test('IP invalid test', () => {
|
||||
const invalidIps = ['255.234.233', '255.255.-1.255', null, undefined, '', 'x.255.y.200'];
|
||||
for (const ip of invalidIps) {
|
||||
expect(() => instance.btreeSearchSync(ip)).toThrow();
|
||||
expect(() => instance.binarySearchSync(ip)).toThrow();
|
||||
}
|
||||
});
|
||||
|
||||
test('File Not Found test', () => {
|
||||
expect(() => new IP2Region({ dbPath: 'A Bad File or Path Here' })).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user