refactoring
This commit is contained in:
parent
7ea1808201
commit
c3e17548b8
|
@ -20,10 +20,11 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const test = require('tape');
|
||||||
const TestSchemaProcessor = require('./TestModules/TestSchemaProcessor');
|
const TestSchemaProcessor = require('./TestModules/TestSchemaProcessor');
|
||||||
const testSchema = require('./TestModules/SchemaProcessorTest');
|
const testSchema = require('./TestModules/SchemaProcessorTest');
|
||||||
const testDataContent = require('./TestModules/DataContentTest');
|
const testDataContent = require('./TestModules/DataContentTest');
|
||||||
const testDataTypes = require('./TestModules/DataTypesTest');
|
const testColumnTypes = require('./TestModules/ColumnTypesTest');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs test suites.
|
* Runs test suites.
|
||||||
|
@ -34,15 +35,22 @@ const testDataTypes = require('./TestModules/DataTypesTest');
|
||||||
*/
|
*/
|
||||||
const runTestSuites = testSchemaProcessor => {
|
const runTestSuites = testSchemaProcessor => {
|
||||||
return () => {
|
return () => {
|
||||||
Promise.all([
|
test.onFinish(() => {
|
||||||
// A list of test suite modules.
|
testSchemaProcessor.removeTestResources()
|
||||||
// Each test suite module must export a function, that returns a promise.
|
.then(() => process.exit());
|
||||||
testSchema(testSchemaProcessor),
|
});
|
||||||
testDataContent(testSchemaProcessor),
|
|
||||||
testDataTypes(testSchemaProcessor),
|
test('Test schema should be created', tapeTestSchema => {
|
||||||
])
|
testSchema(testSchemaProcessor, tapeTestSchema);
|
||||||
.then(() => testSchemaProcessor.removeTestResources())
|
});
|
||||||
.then(() => process.exit());
|
|
||||||
|
test('Test the data content', tapeTestDataContent => {
|
||||||
|
testDataContent(testSchemaProcessor, tapeTestDataContent);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Test column types', tapeTestColumnTypes => {
|
||||||
|
testColumnTypes(testSchemaProcessor, tapeTestColumnTypes);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { test } = require('tape');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `table_a` column types.
|
* Returns `table_a` column types.
|
||||||
*
|
*
|
||||||
|
@ -94,29 +92,26 @@ const getExpectedColumnTypes = () => {
|
||||||
* The data content testing.
|
* The data content testing.
|
||||||
*
|
*
|
||||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||||
|
* @param {Tape} tape
|
||||||
*
|
*
|
||||||
* @returns {Promise<Any>}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
module.exports = testSchemaProcessor => {
|
module.exports = (testSchemaProcessor, tape) => {
|
||||||
return new Promise(resolve => {
|
getColumnTypes(testSchemaProcessor).then(data => {
|
||||||
getColumnTypes(testSchemaProcessor).then(data => {
|
const expectedColumnTypes = getExpectedColumnTypes();
|
||||||
test('Test the data types', tape => {
|
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||||
const expectedColumnTypes = getExpectedColumnTypes();
|
const numberOfPlannedAssertions = data.length;
|
||||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
|
||||||
const numberOfPlannedAssertions = data.length;
|
|
||||||
|
|
||||||
tape.plan(numberOfPlannedAssertions);
|
tape.plan(numberOfPlannedAssertions);
|
||||||
tape.timeoutAfter(autoTimeoutMs);
|
tape.timeoutAfter(autoTimeoutMs);
|
||||||
|
|
||||||
for (let i = 0; i < numberOfPlannedAssertions; ++i) {
|
for (let i = 0; i < numberOfPlannedAssertions; ++i) {
|
||||||
const columnName = data[i].column_name;
|
const columnName = data[i].column_name;
|
||||||
const actualColumnType = data[i].data_type;
|
const actualColumnType = data[i].data_type;
|
||||||
const expectedColumnType = expectedColumnTypes[columnName];
|
const expectedColumnType = expectedColumnTypes[columnName];
|
||||||
tape.equal(actualColumnType, expectedColumnType);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve();
|
tape.comment(`Test ${ columnName } column type`);
|
||||||
});
|
tape.equal(actualColumnType, expectedColumnType);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -20,8 +20,6 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { test } = require('tape');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a data from `table_a`.
|
* Retrieve a data from `table_a`.
|
||||||
*
|
*
|
||||||
|
@ -42,52 +40,91 @@ const retrieveData = testSchemaProcessor => {
|
||||||
* The data content testing.
|
* The data content testing.
|
||||||
*
|
*
|
||||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||||
|
* @param {Tape} tape
|
||||||
*
|
*
|
||||||
* @returns {Promise<Any>}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
module.exports = testSchemaProcessor => {
|
module.exports = (testSchemaProcessor, tape) => {
|
||||||
return new Promise(resolve => {
|
retrieveData(testSchemaProcessor).then(data => {
|
||||||
retrieveData(testSchemaProcessor).then(data => {
|
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||||
test('Test the data content', tape => {
|
const numberOfPlannedAssertions = 24;
|
||||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
const originalTestBlobText = testSchemaProcessor.getTestBlob(testSchemaProcessor._conversion).toString();
|
||||||
const numberOfPlannedAssertions = 24;
|
|
||||||
const originalTestBlobText = testSchemaProcessor
|
|
||||||
.getTestBlob(testSchemaProcessor._conversion)
|
|
||||||
.toString();
|
|
||||||
|
|
||||||
tape.plan(numberOfPlannedAssertions);
|
tape.plan(numberOfPlannedAssertions);
|
||||||
tape.timeoutAfter(autoTimeoutMs);
|
tape.timeoutAfter(autoTimeoutMs);
|
||||||
|
|
||||||
tape.equal(data.blob_text, originalTestBlobText);
|
tape.comment('Test blob_text column value');
|
||||||
tape.equal(data.bit, '1'); // BIT is actually a "bit string", for example: '1110' -> 14
|
tape.equal(data.blob_text, originalTestBlobText);
|
||||||
tape.equal(data.id_test_unique_index, 7384);
|
|
||||||
tape.equal(data.id_test_composite_unique_index_1, 125);
|
|
||||||
tape.equal(data.id_test_composite_unique_index_2, 234);
|
|
||||||
tape.equal(data.id_test_index, 123);
|
|
||||||
tape.equal(data.int_test_not_null, 123);
|
|
||||||
tape.equal(data.id_test_composite_index_1, 11);
|
|
||||||
tape.equal(data.id_test_composite_index_2, 22);
|
|
||||||
tape.equal(JSON.stringify(data.json_test_comment), '{"prop1":"First","prop2":2}');
|
|
||||||
tape.equal(data.year, 1984);
|
|
||||||
tape.equal(data.bigint, '1234567890123456800');
|
|
||||||
tape.equal(data.float, 12345.5);
|
|
||||||
tape.equal(data.double, 123456789.23);
|
|
||||||
tape.equal(data.numeric, '1234567890');
|
|
||||||
tape.equal(data.decimal, '1234567890');
|
|
||||||
tape.equal(data.char_5, 'fghij');
|
|
||||||
tape.equal(data.varchar_5, 'abcde');
|
|
||||||
tape.equal(`${ data.date.getFullYear() }-${ data.date.getMonth() + 1 }-${ data.date.getDate() }`, '1984-11-30');
|
|
||||||
tape.equal(data.time, '21:12:33');
|
|
||||||
tape.equal(data.text, 'Test text');
|
|
||||||
tape.equal(data.enum, 'e1');
|
|
||||||
tape.equal(data.set, 's2');
|
|
||||||
|
|
||||||
const date = `${ data.timestamp.getFullYear() }-${ data.timestamp.getMonth() + 1 }-${ data.timestamp.getDate() }`;
|
tape.comment('Test bit column value');
|
||||||
const time = `${ data.timestamp.getHours() }:${ data.timestamp.getMinutes() }:${ data.timestamp.getSeconds() }`;
|
tape.equal(data.bit, '1'); // BIT is actually a "bit string", for example: '1110' -> 14
|
||||||
tape.equal(`${ date } ${ time }`, '2018-11-11 22:21:20');
|
|
||||||
|
|
||||||
resolve();
|
tape.comment('Test id_test_unique_index column value');
|
||||||
});
|
tape.equal(data.id_test_unique_index, 7384);
|
||||||
});
|
|
||||||
|
tape.comment('Test id_test_composite_unique_index_1 column value');
|
||||||
|
tape.equal(data.id_test_composite_unique_index_1, 125);
|
||||||
|
|
||||||
|
tape.comment('Test id_test_composite_unique_index_2 column value');
|
||||||
|
tape.equal(data.id_test_composite_unique_index_2, 234);
|
||||||
|
|
||||||
|
tape.comment('Test id_test_index column value');
|
||||||
|
tape.equal(data.id_test_index, 123);
|
||||||
|
|
||||||
|
tape.comment('Test int_test_not_null column value');
|
||||||
|
tape.equal(data.int_test_not_null, 123);
|
||||||
|
|
||||||
|
tape.comment('Test id_test_composite_index_1 column value');
|
||||||
|
tape.equal(data.id_test_composite_index_1, 11);
|
||||||
|
|
||||||
|
tape.comment('Test id_test_composite_index_2 column value');
|
||||||
|
tape.equal(data.id_test_composite_index_2, 22);
|
||||||
|
|
||||||
|
tape.comment('Test json_test_comment column value');
|
||||||
|
tape.equal(JSON.stringify(data.json_test_comment), '{"prop1":"First","prop2":2}');
|
||||||
|
|
||||||
|
tape.comment('Test year column value');
|
||||||
|
tape.equal(data.year, 1984);
|
||||||
|
|
||||||
|
tape.comment('Test bigint column value');
|
||||||
|
tape.equal(data.bigint, '1234567890123456800');
|
||||||
|
|
||||||
|
tape.comment('Test float column value');
|
||||||
|
tape.equal(data.float, 12345.5);
|
||||||
|
|
||||||
|
tape.comment('Test double column value');
|
||||||
|
tape.equal(data.double, 123456789.23);
|
||||||
|
|
||||||
|
tape.comment('Test numeric column value');
|
||||||
|
tape.equal(data.numeric, '1234567890');
|
||||||
|
|
||||||
|
tape.comment('Test decimal column value');
|
||||||
|
tape.equal(data.decimal, '1234567890');
|
||||||
|
|
||||||
|
tape.comment('Test char_5 column value');
|
||||||
|
tape.equal(data.char_5, 'fghij');
|
||||||
|
|
||||||
|
tape.comment('Test varchar_5 column value');
|
||||||
|
tape.equal(data.varchar_5, 'abcde');
|
||||||
|
|
||||||
|
tape.comment('Test date column value');
|
||||||
|
tape.equal(`${ data.date.getFullYear() }-${ data.date.getMonth() + 1 }-${ data.date.getDate() }`, '1984-11-30');
|
||||||
|
|
||||||
|
tape.comment('Test time column value');
|
||||||
|
tape.equal(data.time, '21:12:33');
|
||||||
|
|
||||||
|
tape.comment('Test text column value');
|
||||||
|
tape.equal(data.text, 'Test text');
|
||||||
|
|
||||||
|
tape.comment('Test enum column value');
|
||||||
|
tape.equal(data.enum, 'e1');
|
||||||
|
|
||||||
|
tape.comment('Test set column value');
|
||||||
|
tape.equal(data.set, 's2');
|
||||||
|
|
||||||
|
const date = `${ data.timestamp.getFullYear() }-${ data.timestamp.getMonth() + 1 }-${ data.timestamp.getDate() }`;
|
||||||
|
const time = `${ data.timestamp.getHours() }:${ data.timestamp.getMinutes() }:${ data.timestamp.getSeconds() }`;
|
||||||
|
tape.comment('Test timestamp column value');
|
||||||
|
tape.equal(`${ date } ${ time }`, '2018-11-11 22:21:20');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { test } = require('tape');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the schema exists.
|
* Checks if the schema exists.
|
||||||
*
|
*
|
||||||
|
@ -42,24 +40,17 @@ const hasSchemaCreated = testSchemaProcessor => {
|
||||||
* Schema creation testing.
|
* Schema creation testing.
|
||||||
*
|
*
|
||||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||||
|
* @param {Tape} tape
|
||||||
*
|
*
|
||||||
* @returns {Promise<any>}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
module.exports = testSchemaProcessor => {
|
module.exports = (testSchemaProcessor, tape) => {
|
||||||
return new Promise(resolve => {
|
hasSchemaCreated(testSchemaProcessor).then(schemaExists => {
|
||||||
test('Test schema should be created', tape => {
|
const numberOfPlannedAssertions = 1;
|
||||||
const numberOfPlannedAssertions = 2;
|
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
|
||||||
|
|
||||||
tape.plan(numberOfPlannedAssertions);
|
tape.plan(numberOfPlannedAssertions);
|
||||||
tape.timeoutAfter(autoTimeoutMs);
|
tape.timeoutAfter(autoTimeoutMs);
|
||||||
|
tape.equal(schemaExists, true);
|
||||||
hasSchemaCreated(testSchemaProcessor).then(schemaExists => {
|
|
||||||
tape.equal(typeof schemaExists, 'boolean');
|
|
||||||
tape.equal(schemaExists, true);
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue