dbgate/integration-tests/__tests__/table-analyse.spec.js
Jan Prochazka 0d7d0bdd60 cleanup
2021-05-27 13:52:51 +02:00

68 lines
2.1 KiB
JavaScript

const engines = require('../engines');
const { testWrapper } = require('../tools');
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val varchar(50) null)';
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',
}),
],
}),
});
describe('Table analyse', () => {
test.each(engines.map(engine => [engine.label, engine]))(
'Table structure - full analysis (%s)',
testWrapper(async (conn, driver, engine) => {
await driver.query(conn, t1Sql);
const structure = await driver.analyseFull(conn);
expect(structure.tables.length).toEqual(1);
expect(structure.tables[0]).toEqual(t1Match);
})
);
test.each(engines.map(engine => [engine.label, engine]))(
'Table add - incremental analysis (%s)',
testWrapper(async (conn, driver, engine) => {
await driver.query(conn, 'CREATE TABLE t0 (id0 int)');
const structure1 = await driver.analyseFull(conn);
await driver.query(conn, t1Sql);
const structure2 = await driver.analyseIncremental(conn, structure1);
expect(structure2.tables.length).toEqual(2);
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
})
);
test.each(engines.map(engine => [engine.label, engine]))(
'Table remove - incremental analysis (%s)',
testWrapper(async (conn, driver, engine) => {
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);
})
);
});