mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 21:06:00 +00:00
local vs github runs
This commit is contained in:
36
.github/workflows/integration-tests.yaml
vendored
36
.github/workflows/integration-tests.yaml
vendored
@@ -30,35 +30,35 @@ jobs:
|
|||||||
image: postgres
|
image: postgres
|
||||||
env:
|
env:
|
||||||
POSTGRES_PASSWORD: Pwd2020Db
|
POSTGRES_PASSWORD: Pwd2020Db
|
||||||
ports:
|
# ports:
|
||||||
- 5432:5432
|
# - 5432:5432
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
|
||||||
# mysql:
|
mysql:
|
||||||
# image: mysql
|
image: mysql
|
||||||
# # options: >-
|
# options: >-
|
||||||
# # --default-authentication-plugin=mysql_native_password
|
# --default-authentication-plugin=mysql_native_password
|
||||||
# ports:
|
# ports:
|
||||||
# - 15001:3306
|
# - 15001:3306
|
||||||
# env:
|
env:
|
||||||
# MYSQL_ROOT_PASSWORD: Pwd2020Db
|
MYSQL_ROOT_PASSWORD: Pwd2020Db
|
||||||
|
|
||||||
# mssql:
|
mssql:
|
||||||
# image: mcr.microsoft.com/mssql/server
|
image: mcr.microsoft.com/mssql/server
|
||||||
# ports:
|
# ports:
|
||||||
# - 15002:1433
|
# - 15002:1433
|
||||||
# env:
|
env:
|
||||||
# ACCEPT_EULA: Y
|
ACCEPT_EULA: Y
|
||||||
# SA_PASSWORD: Pwd2020Db
|
SA_PASSWORD: Pwd2020Db
|
||||||
# MSSQL_PID: Express
|
MSSQL_PID: Express
|
||||||
|
|
||||||
# cockroachdb:
|
cockroachdb:
|
||||||
# image: cockroachdb/cockroach
|
image: cockroachdb/cockroach
|
||||||
# ports:
|
# ports:
|
||||||
# - 15003:26257
|
# - 15003:26257
|
||||||
# # options: >-
|
# options: >-
|
||||||
# # start-single-node --insecure
|
# start-single-node --insecure
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ const t1Match = expect.objectContaining({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Table analyse', () => {
|
describe('Table analyse', () => {
|
||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
'Table structure - full analysis (%s)',
|
'Table structure - full analysis (%s)',
|
||||||
async (label, engine) => {
|
async (label, engine) => {
|
||||||
const conn = await connect(engine, randomDbName());
|
const conn = await connect(engine, randomDbName());
|
||||||
|
try {
|
||||||
const driver = requireEngineDriver(engine.connection);
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
|
||||||
await driver.query(conn, t1Sql);
|
await driver.query(conn, t1Sql);
|
||||||
@@ -39,8 +41,10 @@ describe('Table analyse', () => {
|
|||||||
|
|
||||||
expect(structure.tables.length).toEqual(1);
|
expect(structure.tables.length).toEqual(1);
|
||||||
expect(structure.tables[0]).toEqual(t1Match);
|
expect(structure.tables[0]).toEqual(t1Match);
|
||||||
|
} finally {
|
||||||
await driver.close(conn);
|
await driver.close(conn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
test.each(engines.map(engine => [engine.label, engine]))(
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
|||||||
@@ -7,26 +7,34 @@ const views = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const engines = [
|
const engines = [
|
||||||
// {
|
{
|
||||||
// label: 'MySQL',
|
label: 'MySQL',
|
||||||
// connection: {
|
connection: {
|
||||||
// engine: 'mysql@dbgate-plugin-mysql',
|
engine: 'mysql@dbgate-plugin-mysql',
|
||||||
// server: 'localhost',
|
password: 'Pwd2020Db',
|
||||||
// password: 'Pwd2020Db',
|
user: 'root',
|
||||||
// user: 'root',
|
server: 'mysql',
|
||||||
// port: 15001,
|
port: 3306,
|
||||||
// },
|
},
|
||||||
// objects: [views],
|
local: {
|
||||||
// },
|
server: 'localhost',
|
||||||
|
port: 15001,
|
||||||
|
},
|
||||||
|
objects: [views],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'PostgreSQL',
|
label: 'PostgreSQL',
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'postgres@dbgate-plugin-postgres',
|
engine: 'postgres@dbgate-plugin-postgres',
|
||||||
server: 'postgres',
|
|
||||||
password: 'Pwd2020Db',
|
password: 'Pwd2020Db',
|
||||||
user: 'postgres',
|
user: 'postgres',
|
||||||
|
server: 'postgres',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
},
|
},
|
||||||
|
local: {
|
||||||
|
server: 'localhost',
|
||||||
|
port: 15000,
|
||||||
|
},
|
||||||
objects: [
|
objects: [
|
||||||
views,
|
views,
|
||||||
{
|
{
|
||||||
@@ -38,44 +46,52 @@ const engines = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// label: 'SQL Server',
|
label: 'SQL Server',
|
||||||
// connection: {
|
connection: {
|
||||||
// engine: 'mssql@dbgate-plugin-mssql',
|
engine: 'mssql@dbgate-plugin-mssql',
|
||||||
// server: 'localhost',
|
password: 'Pwd2020Db',
|
||||||
// password: 'Pwd2020Db',
|
user: 'sa',
|
||||||
// user: 'sa',
|
server: 'mssql',
|
||||||
// port: 15002,
|
port: 1433,
|
||||||
// },
|
},
|
||||||
// objects: [
|
local: {
|
||||||
// views,
|
server: 'localhost',
|
||||||
// {
|
port: 15002,
|
||||||
// type: 'procedures',
|
},
|
||||||
// create1: 'CREATE PROCEDURE obj1 AS SELECT id FROM t1',
|
objects: [
|
||||||
// create2: 'CREATE PROCEDURE obj2 AS SELECT id FROM t2',
|
views,
|
||||||
// drop1: 'DROP PROCEDURE obj1',
|
{
|
||||||
// drop2: 'DROP PROCEDURE obj2',
|
type: 'procedures',
|
||||||
// },
|
create1: 'CREATE PROCEDURE obj1 AS SELECT id FROM t1',
|
||||||
// ],
|
create2: 'CREATE PROCEDURE obj2 AS SELECT id FROM t2',
|
||||||
// },
|
drop1: 'DROP PROCEDURE obj1',
|
||||||
// {
|
drop2: 'DROP PROCEDURE obj2',
|
||||||
// label: 'SQLite',
|
},
|
||||||
// generateDbFile: true,
|
],
|
||||||
// connection: {
|
},
|
||||||
// engine: 'sqlite@dbgate-plugin-sqlite',
|
{
|
||||||
// },
|
label: 'SQLite',
|
||||||
// objects: [views],
|
generateDbFile: true,
|
||||||
// },
|
connection: {
|
||||||
// {
|
engine: 'sqlite@dbgate-plugin-sqlite',
|
||||||
// label: 'CockroachDB',
|
},
|
||||||
// connection: {
|
objects: [views],
|
||||||
// engine: 'cockroach@dbgate-plugin-postgres',
|
},
|
||||||
// server: 'localhost',
|
{
|
||||||
// user: 'root',
|
label: 'CockroachDB',
|
||||||
// port: 15003,
|
connection: {
|
||||||
// },
|
engine: 'cockroach@dbgate-plugin-postgres',
|
||||||
// objects: [views],
|
user: 'root',
|
||||||
// },
|
server: 'cockroachdb',
|
||||||
|
port: 26257,
|
||||||
|
},
|
||||||
|
local: {
|
||||||
|
server: 'localhost',
|
||||||
|
port: 15003,
|
||||||
|
},
|
||||||
|
objects: [views],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = engines;
|
module.exports = engines;
|
||||||
|
|||||||
@@ -9,9 +9,10 @@
|
|||||||
"author": "Jan Prochazka",
|
"author": "Jan Prochazka",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"wait": "cross-env DEVMODE=1 node wait.js",
|
"wait:local": "cross-env DEVMODE=1 LOCALTEST=1 node wait.js",
|
||||||
"test": "cross-env DEVMODE=1 jest",
|
"test": "cross-env DEVMODE=1 jest",
|
||||||
"run:local": "docker-compose down && docker-compose up -d && yarn wait && yarn test"
|
"test:local": "cross-env DEVMODE=1 LOCALTEST=1 jest",
|
||||||
|
"run:local": "docker-compose down && docker-compose up -d && yarn wait:local && yarn test:local"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
|||||||
@@ -8,8 +8,21 @@ function randomDbName() {
|
|||||||
return `db${newKey}`;
|
return `db${newKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connect(engine, database) {
|
function extractConnection(engine) {
|
||||||
const { connection } = engine;
|
const { connection } = engine;
|
||||||
|
|
||||||
|
if (process.env.LOCALTEST && engine.local) {
|
||||||
|
return {
|
||||||
|
...connection,
|
||||||
|
...engine.local,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connect(engine, database) {
|
||||||
|
const connection = extractConnection(engine);
|
||||||
const driver = requireEngineDriver(connection);
|
const driver = requireEngineDriver(connection);
|
||||||
|
|
||||||
if (engine.generateDbFile) {
|
if (engine.generateDbFile) {
|
||||||
@@ -31,7 +44,19 @@ async function connect(engine, database) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const testWrapper = body => async (label, engine, ...other) => {
|
||||||
|
const conn = await connect(engine, randomDbName());
|
||||||
|
try {
|
||||||
|
const driver = requireEngineDriver(engine.connection);
|
||||||
|
await body(driver, engine, ...other);
|
||||||
|
} finally {
|
||||||
|
await driver.close(conn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
randomDbName,
|
randomDbName,
|
||||||
connect,
|
connect,
|
||||||
|
extractConnection,
|
||||||
|
testWrapper,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||||
const engines = require('./engines');
|
const engines = require('./engines');
|
||||||
|
const { extractConnection } = require('./tools');
|
||||||
global.DBGATE_TOOLS = require('dbgate-tools');
|
global.DBGATE_TOOLS = require('dbgate-tools');
|
||||||
|
|
||||||
async function connectEngine(engine) {
|
async function connectEngine(engine) {
|
||||||
const driver = requireEngineDriver(engine.connection);
|
const connection = extractConnection(engine);
|
||||||
|
const driver = requireEngineDriver(connection);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
const conn = await driver.connect(engine.connection);
|
const conn = await driver.connect(connection);
|
||||||
await driver.getVersion(conn);
|
await driver.getVersion(conn);
|
||||||
console.log(`Connect to ${engine.label} - OK`);
|
console.log(`Connect to ${engine.label} - OK`);
|
||||||
await driver.close(conn);
|
await driver.close(conn);
|
||||||
|
|||||||
Reference in New Issue
Block a user