mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
local vs github runs
This commit is contained in:
48
.github/workflows/integration-tests.yaml
vendored
48
.github/workflows/integration-tests.yaml
vendored
@@ -30,35 +30,35 @@ jobs:
|
||||
image: postgres
|
||||
env:
|
||||
POSTGRES_PASSWORD: Pwd2020Db
|
||||
ports:
|
||||
- 5432:5432
|
||||
# ports:
|
||||
# - 5432:5432
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
# mysql:
|
||||
# image: mysql
|
||||
# # options: >-
|
||||
# # --default-authentication-plugin=mysql_native_password
|
||||
# ports:
|
||||
# - 15001:3306
|
||||
# env:
|
||||
# MYSQL_ROOT_PASSWORD: Pwd2020Db
|
||||
mysql:
|
||||
image: mysql
|
||||
# options: >-
|
||||
# --default-authentication-plugin=mysql_native_password
|
||||
# ports:
|
||||
# - 15001:3306
|
||||
env:
|
||||
MYSQL_ROOT_PASSWORD: Pwd2020Db
|
||||
|
||||
# mssql:
|
||||
# image: mcr.microsoft.com/mssql/server
|
||||
# ports:
|
||||
# - 15002:1433
|
||||
# env:
|
||||
# ACCEPT_EULA: Y
|
||||
# SA_PASSWORD: Pwd2020Db
|
||||
# MSSQL_PID: Express
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server
|
||||
# ports:
|
||||
# - 15002:1433
|
||||
env:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: Pwd2020Db
|
||||
MSSQL_PID: Express
|
||||
|
||||
# cockroachdb:
|
||||
# image: cockroachdb/cockroach
|
||||
# ports:
|
||||
# - 15003:26257
|
||||
# # options: >-
|
||||
# # start-single-node --insecure
|
||||
cockroachdb:
|
||||
image: cockroachdb/cockroach
|
||||
# ports:
|
||||
# - 15003:26257
|
||||
# options: >-
|
||||
# start-single-node --insecure
|
||||
|
||||
@@ -26,20 +26,24 @@ const t1Match = expect.objectContaining({
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
describe('Table analyse', () => {
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Table structure - full analysis (%s)',
|
||||
async (label, engine) => {
|
||||
const conn = await connect(engine, randomDbName());
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
try {
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
|
||||
await driver.query(conn, t1Sql);
|
||||
await driver.query(conn, t1Sql);
|
||||
|
||||
const structure = await driver.analyseFull(conn);
|
||||
const structure = await driver.analyseFull(conn);
|
||||
|
||||
expect(structure.tables.length).toEqual(1);
|
||||
expect(structure.tables[0]).toEqual(t1Match);
|
||||
await driver.close(conn);
|
||||
expect(structure.tables.length).toEqual(1);
|
||||
expect(structure.tables[0]).toEqual(t1Match);
|
||||
} finally {
|
||||
await driver.close(conn);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -7,26 +7,34 @@ const views = {
|
||||
};
|
||||
|
||||
const engines = [
|
||||
// {
|
||||
// label: 'MySQL',
|
||||
// connection: {
|
||||
// engine: 'mysql@dbgate-plugin-mysql',
|
||||
// server: 'localhost',
|
||||
// password: 'Pwd2020Db',
|
||||
// user: 'root',
|
||||
// port: 15001,
|
||||
// },
|
||||
// objects: [views],
|
||||
// },
|
||||
{
|
||||
label: 'MySQL',
|
||||
connection: {
|
||||
engine: 'mysql@dbgate-plugin-mysql',
|
||||
password: 'Pwd2020Db',
|
||||
user: 'root',
|
||||
server: 'mysql',
|
||||
port: 3306,
|
||||
},
|
||||
local: {
|
||||
server: 'localhost',
|
||||
port: 15001,
|
||||
},
|
||||
objects: [views],
|
||||
},
|
||||
{
|
||||
label: 'PostgreSQL',
|
||||
connection: {
|
||||
engine: 'postgres@dbgate-plugin-postgres',
|
||||
server: 'postgres',
|
||||
password: 'Pwd2020Db',
|
||||
user: 'postgres',
|
||||
server: 'postgres',
|
||||
port: 5432,
|
||||
},
|
||||
local: {
|
||||
server: 'localhost',
|
||||
port: 15000,
|
||||
},
|
||||
objects: [
|
||||
views,
|
||||
{
|
||||
@@ -38,44 +46,52 @@ const engines = [
|
||||
},
|
||||
],
|
||||
},
|
||||
// {
|
||||
// label: 'SQL Server',
|
||||
// connection: {
|
||||
// engine: 'mssql@dbgate-plugin-mssql',
|
||||
// server: 'localhost',
|
||||
// password: 'Pwd2020Db',
|
||||
// user: 'sa',
|
||||
// port: 15002,
|
||||
// },
|
||||
// objects: [
|
||||
// views,
|
||||
// {
|
||||
// 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',
|
||||
// },
|
||||
// objects: [views],
|
||||
// },
|
||||
// {
|
||||
// label: 'CockroachDB',
|
||||
// connection: {
|
||||
// engine: 'cockroach@dbgate-plugin-postgres',
|
||||
// server: 'localhost',
|
||||
// user: 'root',
|
||||
// port: 15003,
|
||||
// },
|
||||
// objects: [views],
|
||||
// },
|
||||
{
|
||||
label: 'SQL Server',
|
||||
connection: {
|
||||
engine: 'mssql@dbgate-plugin-mssql',
|
||||
password: 'Pwd2020Db',
|
||||
user: 'sa',
|
||||
server: 'mssql',
|
||||
port: 1433,
|
||||
},
|
||||
local: {
|
||||
server: 'localhost',
|
||||
port: 15002,
|
||||
},
|
||||
objects: [
|
||||
views,
|
||||
{
|
||||
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',
|
||||
},
|
||||
objects: [views],
|
||||
},
|
||||
{
|
||||
label: 'CockroachDB',
|
||||
connection: {
|
||||
engine: 'cockroach@dbgate-plugin-postgres',
|
||||
user: 'root',
|
||||
server: 'cockroachdb',
|
||||
port: 26257,
|
||||
},
|
||||
local: {
|
||||
server: 'localhost',
|
||||
port: 15003,
|
||||
},
|
||||
objects: [views],
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = engines;
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
"author": "Jan Prochazka",
|
||||
"license": "MIT",
|
||||
"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",
|
||||
"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": {
|
||||
"cross-env": "^7.0.3",
|
||||
|
||||
@@ -8,8 +8,21 @@ function randomDbName() {
|
||||
return `db${newKey}`;
|
||||
}
|
||||
|
||||
async function connect(engine, database) {
|
||||
function extractConnection(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);
|
||||
|
||||
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 = {
|
||||
randomDbName,
|
||||
connect,
|
||||
extractConnection,
|
||||
testWrapper,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||
const engines = require('./engines');
|
||||
const { extractConnection } = require('./tools');
|
||||
global.DBGATE_TOOLS = require('dbgate-tools');
|
||||
|
||||
async function connectEngine(engine) {
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
const connection = extractConnection(engine);
|
||||
const driver = requireEngineDriver(connection);
|
||||
for (;;) {
|
||||
try {
|
||||
const conn = await driver.connect(engine.connection);
|
||||
const conn = await driver.connect(connection);
|
||||
await driver.getVersion(conn);
|
||||
console.log(`Connect to ${engine.label} - OK`);
|
||||
await driver.close(conn);
|
||||
|
||||
Reference in New Issue
Block a user