MXS-1300: Un-modularize the core

Making the core a module proved to bring more problems than it solved. For
the sake of simplicity in installation and code coverage reporting, the
core is now completely contained in the `lib/` directory.

Also added preliminary coverage reporting with nyc.
This commit is contained in:
Markus Mäkelä
2017-07-19 08:03:44 +03:00
parent 0f1a427458
commit cf8028a5ce
25 changed files with 77 additions and 86 deletions

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'alter <command>' exports.command = 'alter <command>'
exports.desc = 'Alter objects' exports.desc = 'Alter objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'call <command>' exports.command = 'call <command>'
exports.desc = 'Call module commands' exports.desc = 'Call module commands'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'clear <command>' exports.command = 'clear <command>'
exports.desc = 'Clear object state' exports.desc = 'Clear object state'

View File

@ -63,21 +63,21 @@ program
type: 'boolean' type: 'boolean'
}) })
.command(require('./lib/list.js')) .command(require('./list.js'))
.command(require('./lib/show.js')) .command(require('./show.js'))
.command(require('./lib/set.js')) .command(require('./set.js'))
.command(require('./lib/clear.js')) .command(require('./clear.js'))
.command(require('./lib/enable.js')) .command(require('./enable.js'))
.command(require('./lib/disable.js')) .command(require('./disable.js'))
.command(require('./lib/create.js')) .command(require('./create.js'))
.command(require('./lib/destroy.js')) .command(require('./destroy.js'))
.command(require('./lib/link.js')) .command(require('./link.js'))
.command(require('./lib/unlink.js')) .command(require('./unlink.js'))
.command(require('./lib/start.js')) .command(require('./start.js'))
.command(require('./lib/stop.js')) .command(require('./stop.js'))
.command(require('./lib/alter.js')) .command(require('./alter.js'))
.command(require('./lib/rotate.js')) .command(require('./rotate.js'))
.command(require('./lib/call.js')) .command(require('./call.js'))
.help() .help()
.demandCommand(1, 'At least one command is required') .demandCommand(1, 'At least one command is required')
.command('*', 'the default command', {}, () => { .command('*', 'the default command', {}, () => {

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'create <command>' exports.command = 'create <command>'
exports.desc = 'Create objects' exports.desc = 'Create objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'destroy <command>' exports.command = 'destroy <command>'
exports.desc = 'Destroy objects' exports.desc = 'Destroy objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
const log_levels = [ const log_levels = [
'debug', 'debug',

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
const log_levels = [ const log_levels = [
'debug', 'debug',

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
function addServer(argv, path, targets) { function addServer(argv, path, targets) {
maxctrl(argv, function(host){ maxctrl(argv, function(host){

View File

@ -11,7 +11,7 @@
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'list <command>' exports.command = 'list <command>'
exports.desc = 'List objects' exports.desc = 'List objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'rotate <command>' exports.command = 'rotate <command>'
exports.desc = 'Rotate log files' exports.desc = 'Rotate log files'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'set <command>' exports.command = 'set <command>'
exports.desc = 'Set object state' exports.desc = 'Set object state'

View File

@ -11,7 +11,7 @@
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'show <command>' exports.command = 'show <command>'
exports.desc = 'Show objects' exports.desc = 'Show objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'start <command>' exports.command = 'start <command>'
exports.desc = 'Start objects' exports.desc = 'Start objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
exports.command = 'stop <command>' exports.command = 'stop <command>'
exports.desc = 'Stop objects' exports.desc = 'Stop objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General * of this software will be governed by version 2 or later of the General
* Public License. * Public License.
*/ */
require('../common.js')() require('./common.js')()
function removeServer(argv, path, targets) { function removeServer(argv, path, targets) {
maxctrl(argv, function(host) { maxctrl(argv, function(host) {

View File

@ -13,7 +13,7 @@
'use strict'; 'use strict';
var maxctrl = require('maxctrl-core') var maxctrl = require('./lib/core.js')
// Mangle the arguments if we are being called from the command line // Mangle the arguments if we are being called from the command line
if (process.argv[0] == process.execPath) { if (process.argv[0] == process.execPath) {

View File

@ -1,20 +0,0 @@
{
"name": "maxctrl-core",
"version": "1.0.0",
"description": "MaxScale Administrative Client Core Library",
"repository": "https://github.com/mariadb-corporation/MaxScale",
"main": "core.js",
"keywords": [
"maxscale"
],
"author": "MariaDB Corporation Ab",
"license": "SEE LICENSE IN ../../LICENSE.TXT",
"dependencies": {
"cli-table": "^0.3.1",
"lodash": "^4.17.4",
"lodash-getpath": "^0.2.4",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"yargs": "^8.0.2"
}
}

View File

@ -5,7 +5,7 @@
"repository": "https://github.com/mariadb-corporation/MaxScale", "repository": "https://github.com/mariadb-corporation/MaxScale",
"main": "maxctrl.js", "main": "maxctrl.js",
"scripts": { "scripts": {
"test": "mocha --timeout 15000 --slow 10000" "test": "nyc mocha --timeout 15000 --slow 10000"
}, },
"keywords": [ "keywords": [
"maxscale" "maxscale"
@ -14,13 +14,24 @@
"maxctrl": "./maxctrl.js" "maxctrl": "./maxctrl.js"
}, },
"author": "MariaDB Corporation Ab", "author": "MariaDB Corporation Ab",
"license": "SEE LICENSE IN ../../LICENSE.TXT", "license": "SEE LICENSE IN ../LICENSE.TXT",
"dependencies": { "dependencies": {
"maxscale-core": "file:./maxctrl_core" "cli-table": "^0.3.1",
"lodash": "^4.17.4",
"lodash-getpath": "^0.2.4",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"yargs": "^8.0.2"
}, },
"devDependencies": { "devDependencies": {
"chai": "^3.5.0", "chai": "^3.5.0",
"chai-as-promised": "^6.0.0", "chai-as-promised": "^6.0.0",
"mocha": "^3.3.0" "mocha": "^3.3.0",
"nyc": "^11.0.3"
},
"nyc": {
"include": [
"lib/*.js"
]
} }
} }

View File

@ -1,27 +1,27 @@
require('../test_utils.js')() require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var tests = [
'list servers',
'list services',
'list monitors',
'list sessions',
'list filters',
'list modules',
'list users',
'list commands',
'show server server1',
'show service RW-Split-Router',
'show monitor MySQL-Monitor',
'show session 5',
'show filter Hint',
'show module readwritesplit',
'show maxscale',
]
describe("Diagnostic commands", function() { describe("Diagnostic commands", function() {
before(startMaxScale) before(startMaxScale)
var ctrl = require('maxctrl-core')
var tests = [
'list servers',
'list services',
'list monitors',
'list sessions',
'list filters',
'list modules',
'list users',
'list commands',
'show server server1',
'show service RW-Split-Router',
'show monitor MySQL-Monitor',
'show session 5',
'show filter Hint',
'show module readwritesplit',
'show maxscale',
]
tests.forEach(function(i) { tests.forEach(function(i) {
it(i, function() { it(i, function() {
return ctrl.execute(i.split(' '), { return ctrl.execute(i.split(' '), {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')() require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Monitor Commands", function() { describe("Monitor Commands", function() {
before(startMaxScale) before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('create monitor', function() { it('create monitor', function() {
return ctrl.execute('create monitor my-monitor mysqlmon'.split(' '), opts) return ctrl.execute('create monitor my-monitor mysqlmon'.split(' '), opts)
.then(function() { .then(function() {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')() require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Server Commands", function() { describe("Server Commands", function() {
before(startMaxScale) before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('create server', function() { it('create server', function() {
return ctrl.execute('create server server5 127.0.0.1 3003'.split(' '), opts) return ctrl.execute('create server server5 127.0.0.1 3003'.split(' '), opts)
.then(function() { .then(function() {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')() require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Service Commands", function() { describe("Service Commands", function() {
before(startMaxScale) before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('link servers to a service', function() { it('link servers to a service', function() {
return ctrl.execute('link service Read-Connection-Router server1 server2 server3 server4'.split(' '), opts) return ctrl.execute('link service Read-Connection-Router server1 server2 server3 server4'.split(' '), opts)
.then(function() { .then(function() {

View File

@ -1,5 +1,8 @@
require('../test_utils.js')() require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Server states", function() { describe("Server states", function() {
before(function() { before(function() {
return startMaxScale() return startMaxScale()
@ -8,9 +11,6 @@ describe("Server states", function() {
}) })
}) })
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('set correct state', function() { it('set correct state', function() {
return ctrl.execute('set server server2 master'.split(' '), opts) return ctrl.execute('set server server2 master'.split(' '), opts)
.then(function() { .then(function() {