mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 15:33:57 +00:00
integratyion tests WIP
This commit is contained in:
51
integration-tests/__tests__/analyse.spec.js
Normal file
51
integration-tests/__tests__/analyse.spec.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
const engines = require('../engines');
|
||||||
|
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
global.DBGATE_TOOLS = require('dbgate-tools');
|
||||||
|
|
||||||
|
function randomDbName() {
|
||||||
|
const generatedKey = crypto.randomBytes(6);
|
||||||
|
const newKey = generatedKey.toString('hex');
|
||||||
|
return `db${newKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connect(connection, database) {
|
||||||
|
const driver = requireEngineDriver(connection);
|
||||||
|
const conn = await driver.connect(connection);
|
||||||
|
await driver.query(conn, `CREATE DATABASE ${database}`);
|
||||||
|
await driver.close(conn);
|
||||||
|
|
||||||
|
const res = await driver.connect({
|
||||||
|
...connection,
|
||||||
|
database,
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Analyse tests', () => {
|
||||||
|
test.each(engines.map(engine => [engine.label, engine.connection]))(
|
||||||
|
'Create table (%s)',
|
||||||
|
async (label, connection) => {
|
||||||
|
const conn = await connect(connection, randomDbName());
|
||||||
|
const driver = requireEngineDriver(connection);
|
||||||
|
|
||||||
|
await driver.query(conn, 'CREATE TABLE t1 (id int)');
|
||||||
|
|
||||||
|
const structure = await driver.analyseFull(conn);
|
||||||
|
|
||||||
|
expect(structure.tables.length).toEqual(1);
|
||||||
|
expect(structure.tables[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
pureName: 't1',
|
||||||
|
columns: [
|
||||||
|
expect.objectContaining({
|
||||||
|
columnName: 'id',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
await driver.close(conn);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
55
integration-tests/docker-compose.yaml
Normal file
55
integration-tests/docker-compose.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: Pwd2020Db
|
||||||
|
ports:
|
||||||
|
- 15000:5432
|
||||||
|
|
||||||
|
mysql:
|
||||||
|
image: mysql
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 15001:3306
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=Pwd2020Db
|
||||||
|
|
||||||
|
mssql:
|
||||||
|
image: mcr.microsoft.com/mssql/server
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 15002:1433
|
||||||
|
environment:
|
||||||
|
- ACCEPT_EULA=Y
|
||||||
|
- SA_PASSWORD=Pwd2020Db
|
||||||
|
- MSSQL_PID=Express
|
||||||
|
|
||||||
|
# cockroachdb:
|
||||||
|
# image: cockroachdb/cockroach
|
||||||
|
# ports:
|
||||||
|
# - 15003:26257
|
||||||
|
# command: start-single-node --insecure
|
||||||
|
|
||||||
|
# mongodb:
|
||||||
|
# image: mongo:4.0.12
|
||||||
|
# restart: always
|
||||||
|
# volumes:
|
||||||
|
# - mongo-data:/data/db
|
||||||
|
# - mongo-config:/data/configdb
|
||||||
|
# ports:
|
||||||
|
# - 27017:27017
|
||||||
|
|
||||||
|
|
||||||
|
# cockroachdb-init:
|
||||||
|
# image: cockroachdb/cockroach
|
||||||
|
# # build: cockroach
|
||||||
|
# # entrypoint: /cockroach/init.sh
|
||||||
|
# entrypoint: ./cockroach sql --insecure --host="cockroachdb" --execute="CREATE DATABASE IF NOT EXISTS test;"
|
||||||
|
|
||||||
|
# depends_on:
|
||||||
|
# - cockroachdb
|
||||||
|
# restart: on-failure
|
||||||
|
|
||||||
14
integration-tests/engines.js
Normal file
14
integration-tests/engines.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const engines = [
|
||||||
|
{
|
||||||
|
label: 'MySQL',
|
||||||
|
connection: {
|
||||||
|
engine: 'mysql@dbgate-plugin-mysql',
|
||||||
|
server: 'localhost',
|
||||||
|
password: 'Pwd2020Db',
|
||||||
|
user: 'root',
|
||||||
|
port: 15001,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = engines;
|
||||||
21
integration-tests/package.json
Normal file
21
integration-tests/package.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "dbgate-integration-tests",
|
||||||
|
"version": "4.1.1",
|
||||||
|
"homepage": "https://dbgate.org/",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/dbgate/dbgate.git"
|
||||||
|
},
|
||||||
|
"author": "Jan Prochazka",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"prepare": "cross-env DEVMODE=1 node prepare.js",
|
||||||
|
"test": "cross-env DEVMODE=1 jest --runInBand",
|
||||||
|
"start": "docker-compose down && docker-compose up -d && node wait.js && yarn prepare && yarn test"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"jest": "^27.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
14
integration-tests/prepare.js
Normal file
14
integration-tests/prepare.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
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();
|
||||||
6
integration-tests/wait.js
Normal file
6
integration-tests/wait.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
async function run() {
|
||||||
|
console.log('Waiting for starting containers...');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20000));
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"name": "dbgate-all",
|
"name": "dbgate-all",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*",
|
"packages/*",
|
||||||
"plugins/*"
|
"plugins/*",
|
||||||
|
"integration-tests"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start:api": "yarn workspace dbgate-api start",
|
"start:api": "yarn workspace dbgate-api start",
|
||||||
|
|||||||
3
packages/types/engines.d.ts
vendored
3
packages/types/engines.d.ts
vendored
@@ -43,7 +43,8 @@ export interface EngineDriver {
|
|||||||
showConnectionTab?: (tab: 'ssl' | 'sshTunnel', values: any) => boolean;
|
showConnectionTab?: (tab: 'ssl' | 'sshTunnel', values: any) => boolean;
|
||||||
beforeConnectionSave?: (values: any) => any;
|
beforeConnectionSave?: (values: any) => any;
|
||||||
databaseUrlPlaceholder?: string;
|
databaseUrlPlaceholder?: string;
|
||||||
connect({ server, port, user, password, database }): any;
|
connect({ server, port, user, password, database }): Promise<any>;
|
||||||
|
close(pool): Promise<any>;
|
||||||
query(pool: any, sql: string): Promise<QueryResult>;
|
query(pool: any, sql: string): Promise<QueryResult>;
|
||||||
stream(pool: any, sql: string, options: StreamOptions);
|
stream(pool: any, sql: string, options: StreamOptions);
|
||||||
readQuery(pool: any, sql: string, structure?: TableInfo): Promise<stream.Readable>;
|
readQuery(pool: any, sql: string, structure?: TableInfo): Promise<stream.Readable>;
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
connection._database_name = database;
|
connection._database_name = database;
|
||||||
return connection;
|
return connection;
|
||||||
},
|
},
|
||||||
|
async close(pool) {
|
||||||
|
return pool.close();
|
||||||
|
},
|
||||||
async query(connection, sql) {
|
async query(connection, sql) {
|
||||||
if (sql == null) {
|
if (sql == null) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user