Skip to content

Commit

Permalink
fix(doctor): skip some doctor checks for local installs post-install
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Feb 6, 2018
1 parent 710a9d4 commit 324a080
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
22 changes: 19 additions & 3 deletions lib/commands/doctor/checks/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ ${chalk.blue('c)')} run ${chalk.cyan('`ghost install local`')} to get a developm
});
}

function mysqlIsEnabled(ctx) {
// Case 1: instance is already set, which means this check
// is being run post-install. In this case, check the config for sqlite3
// and an external mysql db. If either are found, check is disabled
if (ctx.instance) {
// instance is set, this check is being run post-install
return ctx.instance.config.get('database.client') !== 'sqlite3' &&
includes(['localhost', '127.0.0.1'], ctx.instance.config.get('database.connection.host'));
}

// Case 2: Disable this check if
// a) local install OR
// b) --db sqlite3 is passed OR
// c) --dbhost is passed and IS NOT 'localhost' or '127.0.0.1'
return !ctx.local && ctx.argv.db !== 'sqlite3' &&
(!ctx.argv.dbhost || includes(['localhost', '127.0.0.1'], ctx.argv.dbhost));
}

module.exports = {
title: taskTitle,
task: mysqlCheck,
// Disable this check if:
// a) local install OR
// b) --db sqlite3 is passed OR
// c) --dbhost is passed and IS NOT 'localhost' or '127.0.0.1'
enabled: (ctx) => !ctx.local &&
ctx.argv.db !== 'sqlite3' &&
(!ctx.argv.dbhost || includes(['localhost', '127.0.0.1'], ctx.argv.dbhost)),
enabled: mysqlIsEnabled,
category: ['install']
};
2 changes: 1 addition & 1 deletion lib/commands/doctor/checks/system-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ For local installs we recommend using \`ghost install local\` instead.`,
module.exports = {
title: taskTitle,
task: systemStack,
enabled: (ctx) => !ctx.local,
enabled: (ctx) => !ctx.local && !(ctx.instance && ctx.instance.process.name === 'local'),
skip: (ctx) => !ctx.isDoctorCommand && ctx.argv && !ctx.argv.stack,
category: ['install']
}
47 changes: 39 additions & 8 deletions test/unit/commands/doctor/checks/mysql-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const expect = require('chai').expect;
const sinon = require('sinon');
const configStub = require('../../../../utils/config-stub');

const execa = require('execa');
const errors = require('../../../../../lib/errors');
Expand All @@ -14,14 +15,44 @@ describe('Unit: Doctor Checks > mysql', function () {
sandbox.restore();
});

it('enables works', function () {
expect(mysqlCheck).to.exist;
expect(mysqlCheck.enabled({argv: {}}), 'doesn\'t skip by default').to.be.true;
expect(mysqlCheck.enabled({local: true, argv: {}}), 'skips if local').to.be.false;
expect(mysqlCheck.enabled({argv: {db: 'sqlite3'}}), 'skips if db is sqlite3').to.be.false;
expect(mysqlCheck.enabled({argv: {dbhost: 'localhost'}}), 'no skip if dbhost is localhost').to.be.true;
expect(mysqlCheck.enabled({argv: {dbhost: '127.0.0.1'}}), 'no skip if dbhost is 127.0.0.1').to.be.true;
expect(mysqlCheck.enabled({argv: {dbhost: 'mysql.exernalhost.com'}}), 'skip if dbhost is remote').to.be.false;
describe('enabled', function () {
it('returns false if configured db is sqlite3', function () {
const config = configStub();
config.get.withArgs('database.client').returns('sqlite3');

expect(mysqlCheck.enabled({instance: {config: config}})).to.be.false;
expect(config.get.calledOnce).to.be.true;
});

it('returns false if configured db host is not localhost', function () {
expect(mysqlCheck.enabled).to.exist;

const config = configStub();
config.get.withArgs('database.client').returns('mysql');
config.get.withArgs('database.connection.host').returns('mysql.externalhost.com');

expect(mysqlCheck.enabled({instance: {config: config}})).to.be.false;
expect(config.get.calledTwice).to.be.true;
});

it('returns true if configured db host is localhost', function () {
expect(mysqlCheck.enabled).to.exist;

const config = configStub();
config.get.withArgs('database.client').returns('mysql');
config.get.withArgs('database.connection.host').returns('localhost');

expect(mysqlCheck.enabled({instance: {config: config}})).to.be.true;
expect(config.get.calledTwice).to.be.true;
});

it('works correctly with various arguments', function () {
expect(mysqlCheck.enabled({local: true, argv: {}}), 'false if local').to.be.false;
expect(mysqlCheck.enabled({argv: {db: 'sqlite3'}}), 'skips if db is sqlite3').to.be.false;
expect(mysqlCheck.enabled({argv: {dbhost: 'localhost'}}), 'no skip if dbhost is localhost').to.be.true;
expect(mysqlCheck.enabled({argv: {dbhost: '127.0.0.1'}}), 'no skip if dbhost is 127.0.0.1').to.be.true;
expect(mysqlCheck.enabled({argv: {dbhost: 'mysql.exernalhost.com'}}), 'skip if dbhost is remote').to.be.false;
});
});

it('appends sbin to path if platform is linux', function () {
Expand Down
11 changes: 9 additions & 2 deletions test/unit/commands/doctor/checks/system-stack-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ describe('Unit: Doctor Checks > systemStack', function () {
});

it('enabled works', function () {
expect(systemStack.enabled({local: false})).to.be.true;
expect(systemStack.enabled({local: true})).to.be.false;
expect(systemStack.enabled({local: true}), 'false if local is true').to.be.false;
expect(systemStack.enabled({
local: false,
instance: {process: {name: 'local'}}
}), 'false if local is false and process name is local').to.be.false;
expect(systemStack.enabled({
local: false,
instance: {process: {name: 'systemd'}}
}), 'true if local is false and process name is not local').to.be.true;
});

it('skip works', function () {
Expand Down

0 comments on commit 324a080

Please sign in to comment.