dbgate/integration-tests/__tests__/table-analyse.spec.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-05-27 07:12:21 +00:00
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
2021-05-27 08:28:52 +00:00
const engines = require('../engines');
const { connect, randomDbName } = require('../tools');
2021-05-27 07:12:21 +00:00
2021-05-27 08:28:52 +00:00
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val varchar(50) null)';
2021-05-27 08:16:05 +00:00
const t1Match = expect.objectContaining({
pureName: 't1',
columns: [
expect.objectContaining({
columnName: 'id',
notNull: true,
dataType: expect.stringContaining('int'),
}),
expect.objectContaining({
columnName: 'val',
notNull: false,
dataType: expect.stringMatching(/.*char.*\(50\)/),
}),
],
primaryKey: expect.objectContaining({
columns: [
expect.objectContaining({
columnName: 'id',
}),
],
}),
});
2021-05-27 07:43:08 +00:00
2021-05-27 11:07:58 +00:00
2021-05-27 10:26:20 +00:00
describe('Table analyse', () => {
2021-05-27 07:43:08 +00:00
test.each(engines.map(engine => [engine.label, engine]))(
'Table structure - full analysis (%s)',
async (label, engine) => {
const conn = await connect(engine, randomDbName());
2021-05-27 11:07:58 +00:00
try {
const driver = requireEngineDriver(engine.connection);
2021-05-27 07:12:21 +00:00
2021-05-27 11:07:58 +00:00
await driver.query(conn, t1Sql);
2021-05-27 07:12:21 +00:00
2021-05-27 11:07:58 +00:00
const structure = await driver.analyseFull(conn);
2021-05-27 07:12:21 +00:00
2021-05-27 11:07:58 +00:00
expect(structure.tables.length).toEqual(1);
expect(structure.tables[0]).toEqual(t1Match);
} finally {
await driver.close(conn);
}
2021-05-27 07:12:21 +00:00
}
);
2021-05-27 07:26:37 +00:00
2021-05-27 07:43:08 +00:00
test.each(engines.map(engine => [engine.label, engine]))(
2021-05-27 07:26:37 +00:00
'Table add - incremental analysis (%s)',
2021-05-27 07:43:08 +00:00
async (label, engine) => {
const conn = await connect(engine, randomDbName());
const driver = requireEngineDriver(engine.connection);
2021-05-27 07:26:37 +00:00
2021-05-27 08:16:05 +00:00
await driver.query(conn, 'CREATE TABLE t0 (id0 int)');
2021-05-27 07:26:37 +00:00
const structure1 = await driver.analyseFull(conn);
2021-05-27 08:16:05 +00:00
await driver.query(conn, t1Sql);
2021-05-27 07:26:37 +00:00
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2.tables.length).toEqual(2);
2021-05-27 08:16:05 +00:00
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
2021-05-27 07:26:37 +00:00
await driver.close(conn);
}
);
2021-05-27 08:16:05 +00:00
test.each(engines.map(engine => [engine.label, engine]))(
'Table remove - incremental analysis (%s)',
async (label, engine) => {
const conn = await connect(engine, randomDbName());
const driver = requireEngineDriver(engine.connection);
await driver.query(conn, t1Sql);
await driver.query(conn, 'CREATE TABLE t2 (id2 int)');
const structure1 = await driver.analyseFull(conn);
await driver.query(conn, 'DROP TABLE t2');
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2.tables.length).toEqual(1);
expect(structure2.tables[0]).toEqual(t1Match);
await driver.close(conn);
}
);
2021-05-27 07:12:21 +00:00
});