mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 06:43:59 +00:00
integration tests WIP
This commit is contained in:
@@ -25,7 +25,7 @@ async function connect(connection, database) {
|
|||||||
|
|
||||||
describe('Analyse tests', () => {
|
describe('Analyse tests', () => {
|
||||||
test.each(engines.map(engine => [engine.label, engine.connection]))(
|
test.each(engines.map(engine => [engine.label, engine.connection]))(
|
||||||
'Create table (%s)',
|
'Table - full analysis (%s)',
|
||||||
async (label, connection) => {
|
async (label, connection) => {
|
||||||
const conn = await connect(connection, randomDbName());
|
const conn = await connect(connection, randomDbName());
|
||||||
const driver = requireEngineDriver(connection);
|
const driver = requireEngineDriver(connection);
|
||||||
@@ -48,4 +48,30 @@ describe('Analyse tests', () => {
|
|||||||
await driver.close(conn);
|
await driver.close(conn);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.each(engines.map(engine => [engine.label, engine.connection]))(
|
||||||
|
'Table add - incremental analysis (%s)',
|
||||||
|
async (label, connection) => {
|
||||||
|
const conn = await connect(connection, randomDbName());
|
||||||
|
const driver = requireEngineDriver(connection);
|
||||||
|
|
||||||
|
await driver.query(conn, 'CREATE TABLE t1 (id int)');
|
||||||
|
const structure1 = await driver.analyseFull(conn);
|
||||||
|
await driver.query(conn, 'CREATE TABLE t2 (id2 int)');
|
||||||
|
const structure2 = await driver.analyseIncremental(conn, structure1);
|
||||||
|
|
||||||
|
expect(structure2.tables.length).toEqual(2);
|
||||||
|
expect(structure2.tables.find(x => x.pureName == 't2')).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
pureName: 't2',
|
||||||
|
columns: [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'id2',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
await driver.close(conn);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,26 @@ const engines = [
|
|||||||
port: 15001,
|
port: 15001,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'PostgreSQL',
|
||||||
|
connection: {
|
||||||
|
engine: 'postgres@dbgate-plugin-postgres',
|
||||||
|
server: 'localhost',
|
||||||
|
password: 'Pwd2020Db',
|
||||||
|
user: 'postgres',
|
||||||
|
port: 15000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'SQL Server',
|
||||||
|
connection: {
|
||||||
|
engine: 'mssql@dbgate-plugin-mssql',
|
||||||
|
server: 'localhost',
|
||||||
|
password: 'Pwd2020Db',
|
||||||
|
user: 'sa',
|
||||||
|
port: 15002,
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = engines;
|
module.exports = engines;
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
"author": "Jan Prochazka",
|
"author": "Jan Prochazka",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "cross-env DEVMODE=1 node prepare.js",
|
"wait": "cross-env DEVMODE=1 node wait.js",
|
||||||
"test": "cross-env DEVMODE=1 jest --runInBand",
|
"test": "cross-env DEVMODE=1 jest --runInBand",
|
||||||
"start": "docker-compose down && docker-compose up -d && node wait.js && yarn prepare && yarn test"
|
"run:all": "docker-compose down && docker-compose up -d && yarn wait && yarn test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
|
||||||
const engines = require('./engines');
|
|
||||||
global.DBGATE_TOOLS = require('dbgate-tools');
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
for (const engine of engines) {
|
|
||||||
const driver = requireEngineDriver(engine.connection);
|
|
||||||
const conn = await driver.connect(engine.connection);
|
|
||||||
await driver.query(conn, 'CREATE DATABASE dbtest');
|
|
||||||
await driver.close(conn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,6 +1,23 @@
|
|||||||
|
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||||
|
const engines = require('./engines');
|
||||||
|
global.DBGATE_TOOLS = require('dbgate-tools');
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
console.log('Waiting for starting containers...');
|
for (const engine of engines) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 20000));
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
for (;;) {
|
||||||
|
try {
|
||||||
|
const conn = await driver.connect(engine.connection);
|
||||||
|
await driver.getVersion(conn);
|
||||||
|
await driver.close(conn);
|
||||||
|
break;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Waiting for ${engine.label}`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ const driver = {
|
|||||||
|
|
||||||
return tediousConnect(conn);
|
return tediousConnect(conn);
|
||||||
},
|
},
|
||||||
|
async close(pool) {
|
||||||
|
return pool.close();
|
||||||
|
},
|
||||||
async queryCore(pool, sql, options) {
|
async queryCore(pool, sql, options) {
|
||||||
if (pool._connectionType == 'msnodesqlv8') {
|
if (pool._connectionType == 'msnodesqlv8') {
|
||||||
return nativeQueryCore(pool, sql, options);
|
return nativeQueryCore(pool, sql, options);
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
await client.connect();
|
await client.connect();
|
||||||
return client;
|
return client;
|
||||||
},
|
},
|
||||||
|
async close(pool) {
|
||||||
|
return pool.end();
|
||||||
|
},
|
||||||
async query(client, sql) {
|
async query(client, sql) {
|
||||||
if (sql == null) {
|
if (sql == null) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user