migrating to typescript
This commit is contained in:
parent
08500d4441
commit
85958c0de8
|
@ -31,8 +31,7 @@ import { createDataPoolTable, readDataPool } from './DataPoolManager';
|
|||
import log from './Logger';
|
||||
import { Stats } from 'fs';
|
||||
|
||||
const Main = class {
|
||||
|
||||
export class Main {
|
||||
/**
|
||||
* Read the configuration file.
|
||||
*/
|
||||
|
@ -115,10 +114,9 @@ const Main = class {
|
|||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Main;
|
||||
const app = new Main();
|
||||
const app: Main = new Main();
|
||||
const baseDir: string = path.join(__dirname, '..', '..');
|
||||
|
||||
app.readConfig(baseDir)
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
const getColumnTypes = testSchemaProcessor => {
|
||||
const sql = `SELECT column_name, data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_catalog = '${ testSchemaProcessor._conversion._targetConString.database }'
|
||||
AND table_schema = '${ testSchemaProcessor._conversion._schema }'
|
||||
WHERE table_catalog = '${ testSchemaProcessor.conversion._targetConString.database }'
|
||||
AND table_schema = '${ testSchemaProcessor.conversion._schema }'
|
||||
AND table_name = 'table_a';`;
|
||||
|
||||
return testSchemaProcessor
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
const retrieveData = testSchemaProcessor => {
|
||||
const sql = `SELECT ENCODE(table_a.blob, 'escape') AS blob_text, table_a.*
|
||||
FROM ${ testSchemaProcessor._conversion._schema }.table_a AS table_a;`;
|
||||
FROM ${ testSchemaProcessor.conversion._schema }.table_a AS table_a;`;
|
||||
|
||||
return testSchemaProcessor
|
||||
.queryPg(sql)
|
||||
|
@ -48,7 +48,7 @@ module.exports = (testSchemaProcessor, tape) => {
|
|||
retrieveData(testSchemaProcessor).then(data => {
|
||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||
const numberOfPlannedAssertions = 24;
|
||||
const originalTestBlobText = testSchemaProcessor.getTestBlob(testSchemaProcessor._conversion).toString();
|
||||
const originalTestBlobText = testSchemaProcessor.getTestBlob(testSchemaProcessor.conversion).toString();
|
||||
|
||||
tape.plan(numberOfPlannedAssertions);
|
||||
tape.timeoutAfter(autoTimeoutMs);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
const hasSchemaCreated = testSchemaProcessor => {
|
||||
const sql = `SELECT EXISTS(SELECT schema_name FROM information_schema.schemata
|
||||
WHERE schema_name = '${ testSchemaProcessor._conversion._schema }');`;
|
||||
WHERE schema_name = '${ testSchemaProcessor.conversion._schema }');`;
|
||||
|
||||
return testSchemaProcessor
|
||||
.queryPg(sql)
|
||||
|
|
|
@ -43,14 +43,14 @@ export default class TestSchemaProcessor {
|
|||
/**
|
||||
* Instance of class Conversion.
|
||||
*/
|
||||
private _conversion?: Conversion;
|
||||
public conversion?: Conversion;
|
||||
|
||||
/**
|
||||
* TestSchemaProcessor constructor.
|
||||
*/
|
||||
public constructor() {
|
||||
this._app = new Main();
|
||||
this._conversion = undefined;
|
||||
this.conversion = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,37 +69,37 @@ export default class TestSchemaProcessor {
|
|||
*/
|
||||
removeTestResources() {
|
||||
return new Promise(resolve => {
|
||||
if (!this._conversion._removeTestResources) {
|
||||
if (!this.conversion._removeTestResources) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
return connect(this._conversion).then(() => {
|
||||
this._conversion._mysql.getConnection((mysqlConErr, connection) => {
|
||||
return connect(this.conversion).then(() => {
|
||||
this.conversion._mysql.getConnection((mysqlConErr, connection) => {
|
||||
if (mysqlConErr) {
|
||||
// The connection is undefined.
|
||||
this.processFatalError(this._conversion, mysqlConErr);
|
||||
this.processFatalError(this.conversion, mysqlConErr);
|
||||
}
|
||||
|
||||
connection.query(`DROP DATABASE ${ this._conversion._mySqlDbName };`, mysqlDropErr => {
|
||||
connection.query(`DROP DATABASE ${ this.conversion._mySqlDbName };`, mysqlDropErr => {
|
||||
connection.release();
|
||||
|
||||
if (mysqlDropErr) {
|
||||
// Failed to drop test source database.
|
||||
this.processFatalError(this._conversion, mysqlDropErr);
|
||||
this.processFatalError(this.conversion, mysqlDropErr);
|
||||
}
|
||||
|
||||
this._conversion._pg.connect((pgConErr, client, release) => {
|
||||
this.conversion._pg.connect((pgConErr, client, release) => {
|
||||
if (pgConErr) {
|
||||
//The connection is undefined.
|
||||
this.processFatalError(this._conversion, pgConErr);
|
||||
this.processFatalError(this.conversion, pgConErr);
|
||||
}
|
||||
|
||||
client.query(`DROP SCHEMA ${ this._conversion._schema } CASCADE;`, pgDropErr => {
|
||||
client.query(`DROP SCHEMA ${ this.conversion._schema } CASCADE;`, pgDropErr => {
|
||||
release();
|
||||
|
||||
if (pgDropErr) {
|
||||
// Failed to drop test target schema.
|
||||
this.processFatalError(this._conversion, pgDropErr);
|
||||
this.processFatalError(this.conversion, pgDropErr);
|
||||
}
|
||||
|
||||
resolve();
|
||||
|
@ -127,7 +127,7 @@ export default class TestSchemaProcessor {
|
|||
this.processFatalError(conversion, error);
|
||||
}
|
||||
|
||||
connection.query(`CREATE DATABASE IF NOT EXISTS ${ this._conversion._mySqlDbName };`, err => {
|
||||
connection.query(`CREATE DATABASE IF NOT EXISTS ${ this.conversion._mySqlDbName };`, err => {
|
||||
connection.release();
|
||||
|
||||
if (err) {
|
||||
|
@ -297,11 +297,11 @@ export default class TestSchemaProcessor {
|
|||
.then(config => this._app.readExtraConfig(config, baseDir))
|
||||
.then(this._app.initializeConversion)
|
||||
.then(conversion => {
|
||||
this._conversion = conversion;
|
||||
this._conversion._runsInTestMode = true;
|
||||
this._conversion._eventEmitter = new EventEmitter();
|
||||
delete this._conversion._sourceConString.database;
|
||||
return Promise.resolve(this._conversion);
|
||||
this.conversion = conversion;
|
||||
this.conversion._runsInTestMode = true;
|
||||
this.conversion._eventEmitter = new EventEmitter();
|
||||
delete this.conversion._sourceConString.database;
|
||||
return Promise.resolve(this.conversion);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -338,18 +338,18 @@ export default class TestSchemaProcessor {
|
|||
* @returns {Promise<pg.Result>}
|
||||
*/
|
||||
queryPg(sql) {
|
||||
return connect(this._conversion).then(() => {
|
||||
return connect(this.conversion).then(() => {
|
||||
return new Promise(resolve => {
|
||||
this._conversion._pg.connect((error, client, release) => {
|
||||
this.conversion._pg.connect((error, client, release) => {
|
||||
if (error) {
|
||||
this.processFatalError(this._conversion, error);
|
||||
this.processFatalError(this.conversion, error);
|
||||
}
|
||||
|
||||
client.query(sql, (err, data) => {
|
||||
release();
|
||||
|
||||
if (err) {
|
||||
this.processFatalError(this._conversion, err);
|
||||
this.processFatalError(this.conversion, err);
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
|
|
Loading…
Reference in a new issue