knex/test/tape/invalid-db-setup.js
Mikael Lepistö 8a9a648ae2
Docker based test dbs (#3157)
* Fixed some of the tests failing with various dialect combinations

* Setup all test databases to run in docker

* Fixed test suite and updated travis to use docker

* Fixed some tests in master and disabled oracle tests while setting everything else to work again

* Changed docker to use latest postgresql alpine image

* Re-enabled all oracledb tests

* Install oracle client libs to oracle server and copy them to travis to make node oracledb package to work

* Disabled random failing oracle tests and added test to show that oracle update in transaction does not seem to work ACID

* Update package.json

* Update package.json

* Fixed linting issues

* Fixed waiting for postgres to use the same DB image that database is using.

* Removed installing oracledb driver in travis if not needed .travis.yml

* Cleaned up package.json more

* Created static name for oracledb container to allow copying files out of it on different docker versions

* Removed webpack from deps
2019-05-13 12:21:36 +03:00

129 lines
3.8 KiB
JavaScript

'use strict';
const tape = require('tape');
const _ = require('lodash');
const makeKnex = require('../../knex');
const Bluebird = require('bluebird');
module.exports = (knexfile) => {
Object.keys(knexfile).forEach((key) => {
const dialect = knexfile[key].dialect || knexfile[key].client;
// TODO: FIX ORACLE AND MSSQL TO WORK THE SAME WAY WITH OTHER DIALECTS IF POSSIBLE
if (
dialect !== 'sqlite3' &&
dialect !== 'oracledb' &&
dialect !== 'mssql'
) {
const knexConf = _.cloneDeep(knexfile[key]);
knexConf.connection.database = knexConf.connection.db =
'i-refuse-to-exist';
knexConf.acquireConnectionTimeout = 4000;
const knex = makeKnex(knexConf);
tape(dialect + ' - propagate error when DB does not exist', (t) => {
t.plan(1);
t.timeoutAfter(1000);
knex('accounts')
.select(1)
.then((res) => {
t.fail(`Query should have failed, got: ${JSON.stringify(res)}`);
})
.catch(Bluebird.TimeoutError, (e) => {
t.fail(`Query should have failed with non timeout error`);
})
.catch((e) => {
t.ok(
e.message.indexOf('i-refuse-to-exist') > 0,
`all good, failed as expected with msg: ${e.message}`
);
});
});
tape(
dialect + ' - propagate error when DB does not exist for stream',
(t) => {
t.plan(1);
t.timeoutAfter(1000);
knex
.select(1)
.stream((stream) => {})
.then((res) => {
t.fail(
`Stream query should have failed, got: ${JSON.stringify(res)}`
);
})
.catch(Bluebird.TimeoutError, (e) => {
t.fail(`Stream query should have failed with non timeout error`);
})
.catch((e) => {
t.ok(
e.message.indexOf('i-refuse-to-exist') > 0,
`all good, failed as expected with msg: ${e.message}`
);
});
}
);
tape.onFinish(() => {
knex.destroy();
});
}
if (dialect !== 'sqlite3') {
const knexConf = _.cloneDeep(knexfile[key]);
knexConf.acquireConnectionTimeout = 100;
knexConf.pool = { max: 1, min: 1, acquireTimeoutMillis: 100 };
const knex = makeKnex(knexConf);
tape.onFinish(() => {
knex.destroy();
});
tape(dialect + ' - acquireConnectionTimeout works', (t) => {
if (dialect === 'oracledb') {
t.skip(
'!!!!!!! acquireConnectionTimeout fails with oracledb! please fix. !!!!!!!!'
);
t.end();
return;
}
t.plan(2);
t.timeoutAfter(1000);
// just hog the only connection.
knex
.transaction((trx) => {
// Don't return this promise! Also note that we use `knex` instead of `trx`
// here on purpose. The only reason this code is here, is that we can be
// certain `trx` has been created before this.
knex('accounts')
.select(1)
.then(() => {
t.fail('query should have stalled');
})
.catch(Bluebird.TimeoutError, (e) => {
t.pass('Got acquireTimeout error');
})
.catch((e) => {
t.fail(
`should have got acquire timeout error, but got ${
e.message
} instead.`
);
})
.finally(() => {
trx.commit(); // release stuff
});
})
.then(() => {
t.pass('transaction was resolved');
t.end();
});
});
}
});
};