mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated tests to use DatabaseInfo
- some code in tests were still using various unreliable methods to determine the database in use - DatabaseInfo is the correct method to check if the db is mysql or sqlite - Exposed DatabaseInfo via our test db-utils to make this easier
This commit is contained in:
parent
1033e7be21
commit
83ad79308b
2 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,7 @@ const url = require('url');
|
|||
const configUtils = require('../../utils/configUtils');
|
||||
const config = require('../../../core/shared/config');
|
||||
const testUtils = require('../../utils');
|
||||
const dbUtils = require('../../utils/db-utils');
|
||||
const localUtils = require('./utils');
|
||||
|
||||
describe('Tags Content API', function () {
|
||||
|
@ -40,7 +41,7 @@ describe('Tags Content API', function () {
|
|||
// Default order 'name asc' check
|
||||
// the ordering difference is described in https://github.com/TryGhost/Ghost/issues/6104
|
||||
// this condition should be removed once issue mentioned above ^ is resolved
|
||||
if (process.env.NODE_ENV === 'testing-mysql') {
|
||||
if (dbUtils.isMySQL()) {
|
||||
jsonResponse.tags[0].name.should.eql('bacon');
|
||||
jsonResponse.tags[3].name.should.eql('kitchen sink');
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,7 @@ const fs = require('fs-extra');
|
|||
const Promise = require('bluebird');
|
||||
const KnexMigrator = require('knex-migrator');
|
||||
const knexMigrator = new KnexMigrator();
|
||||
const DatabaseInfo = require('@tryghost/database-info');
|
||||
|
||||
// Ghost Internals
|
||||
const config = require('../../core/shared/config');
|
||||
|
@ -17,9 +18,17 @@ const urlServiceUtils = require('./url-service-utils');
|
|||
|
||||
const dbHash = Date.now();
|
||||
|
||||
module.exports.isMySQL = () => {
|
||||
return DatabaseInfo.isMySQL(db.knex);
|
||||
};
|
||||
|
||||
module.exports.isSQLite = () => {
|
||||
return DatabaseInfo.isSQLite(db.knex);
|
||||
};
|
||||
|
||||
module.exports.reset = async ({truncate} = {truncate: false}) => {
|
||||
// Only run this copy in CI until it gets fleshed out
|
||||
if (process.env.CI && config.get('database:client') === 'sqlite3') {
|
||||
if (process.env.CI && module.exports.isSQLite()) {
|
||||
const filename = config.get('database:connection:filename');
|
||||
const filenameOrig = `${filename}.${dbHash}-orig`;
|
||||
|
||||
|
@ -58,7 +67,7 @@ module.exports.initData = async () => {
|
|||
};
|
||||
|
||||
module.exports.truncate = async (tableName) => {
|
||||
if (config.get('database:client') === 'sqlite3') {
|
||||
if (module.exports.isSQLite()) {
|
||||
const [foreignKeysEnabled] = await db.knex.raw('PRAGMA foreign_keys;');
|
||||
if (foreignKeysEnabled.foreign_keys) {
|
||||
await db.knex.raw('PRAGMA foreign_keys = OFF;');
|
||||
|
@ -92,7 +101,7 @@ module.exports.teardown = () => {
|
|||
|
||||
const tables = schemaTables.concat(['migrations']);
|
||||
|
||||
if (config.get('database:client') === 'sqlite3') {
|
||||
if (module.exports.isSQLite()) {
|
||||
return Promise
|
||||
.mapSeries(tables, function createTable(table) {
|
||||
return (async function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue