From c9f3d014d633a43772ae6ac6c5a864d9ecd6fd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sat, 22 Jul 2017 02:53:39 +0300 Subject: [PATCH] MXS-1300: Improve test coverage The tests now cover 100% of all source files with the exception of the call.js and common.js source files. --- maxctrl/lib/core.js | 6 ++++-- maxctrl/test/alter.js | 3 --- maxctrl/test/createdestroy.js | 33 +++++++++++++++++++++++++++++++++ maxctrl/test/diagnostics.js | 7 +++---- maxctrl/test/enabledisable.js | 35 ++++++++++++++++++++++++++++------- maxctrl/test/link.js | 5 +---- maxctrl/test/rotate.js | 12 ++++++++++++ maxctrl/test/special.js | 20 ++++++++++++++++++++ maxctrl/test/startstop.js | 3 --- maxctrl/test/states.js | 5 +---- maxctrl/test/unknown.js | 7 +++++++ 11 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 maxctrl/test/rotate.js create mode 100644 maxctrl/test/special.js diff --git a/maxctrl/lib/core.js b/maxctrl/lib/core.js index 09d778abf..be945f8ee 100644 --- a/maxctrl/lib/core.js +++ b/maxctrl/lib/core.js @@ -80,8 +80,10 @@ program .command(require('./call.js')) .help() .demandCommand(1, 'At least one command is required') - .command('*', 'the default command', {}, () => { - console.log('Unknown command. See output of `help` for a list of commands.') + .command('*', 'the default command', {}, function(argv) { + maxctrl(argv, function() { + return error('Unknown command. See output of `help` for a list of commands.') + }) }) module.exports.execute = function(argv, opts) { diff --git a/maxctrl/test/alter.js b/maxctrl/test/alter.js index 82ec29b9a..565d1105b 100644 --- a/maxctrl/test/alter.js +++ b/maxctrl/test/alter.js @@ -1,8 +1,5 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - describe("Alter Commands", function() { before(startMaxScale) diff --git a/maxctrl/test/createdestroy.js b/maxctrl/test/createdestroy.js index 33c38603b..e186fc4b5 100644 --- a/maxctrl/test/createdestroy.js +++ b/maxctrl/test/createdestroy.js @@ -90,6 +90,17 @@ describe("Create/Destroy Commands", function() { }) }) + it('create server for service and monitor', function() { + return verifyCommand('create server server6 127.0.0.1 3005 --services RW-Split-Router --monitors MySQL-Monitor', + 'servers/server6') + .then(function(res) { + res.data.relationships.services.data[0].id.should.equal("RW-Split-Router") + res.data.relationships.services.data.length.should.equal(1) + res.data.relationships.monitors.data[0].id.should.equal("MySQL-Monitor") + res.data.relationships.monitors.data.length.should.equal(1) + }) + }) + it('create already existing server', function() { return doCommand('create server server1 127.0.0.1 3000') .should.be.rejected @@ -100,5 +111,27 @@ describe("Create/Destroy Commands", function() { .should.be.rejected }) + it('create listener', function() { + return verifyCommand('create listener RW-Split-Router my-listener 4567', + 'services/RW-Split-Router/listeners/my-listener') + .should.be.fulfilled + }) + + it('destroy listener', function() { + return doCommand('destroy listener RW-Split-Router my-listener') + .should.be.fulfilled + }) + + it('create user', function() { + return verifyCommand('create user testuser test', + 'users/inet/testuser') + .should.be.fulfilled + }) + + it('destroy user', function() { + return doCommand('destroy user testuser') + .should.be.fulfilled + }) + after(stopMaxScale) }); diff --git a/maxctrl/test/diagnostics.js b/maxctrl/test/diagnostics.js index 5b67c5625..e33bdda89 100644 --- a/maxctrl/test/diagnostics.js +++ b/maxctrl/test/diagnostics.js @@ -1,8 +1,5 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - var tests = [ 'list servers', 'list services', @@ -20,9 +17,11 @@ var tests = [ 'show filter Hint', 'show module readwritesplit', 'show maxscale', + 'show logging', + 'show commands readwritesplit', ] -describe("Diagnostic commands", function() { +describe("Diagnostic Commands", function() { before(startMaxScale) tests.forEach(function(i) { diff --git a/maxctrl/test/enabledisable.js b/maxctrl/test/enabledisable.js index 6c4af038c..87d356e51 100644 --- a/maxctrl/test/enabledisable.js +++ b/maxctrl/test/enabledisable.js @@ -1,20 +1,41 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - describe("Enable/Disable Commands", function() { before(startMaxScale) - it('disable with bad parameter', function() { - return doCommand('disable log-priority bad-stuff') - .should.be.rejected + it('enable log-priority', function() { + return verifyCommand('enable log-priority info', 'maxscale/logs') + .then(function(res) { + res.data.attributes.log_priorities.should.include('info') + }) }) - it('enable with bad parameter', function() { + it('disable log-priority', function() { + return verifyCommand('disable log-priority info', 'maxscale/logs') + .then(function(res) { + res.data.attributes.log_priorities.should.not.include('info') + }) + }) + + it('enable log-priority with bad parameter', function() { return doCommand('enable log-priority bad-stuff') .should.be.rejected }) + it('disable log-priority with bad parameter', function() { + return doCommand('disable log-priority bad-stuff') + .should.be.rejected + }) + + it('enable account', function() { + return verifyCommand('enable account test', 'users/unix/test') + .should.be.fulfilled + }) + + it('disable account', function() { + return doCommand('disable account test') + .should.be.fulfilled + }) + after(stopMaxScale) }); diff --git a/maxctrl/test/link.js b/maxctrl/test/link.js index 9c1599bf1..22af8da7f 100644 --- a/maxctrl/test/link.js +++ b/maxctrl/test/link.js @@ -1,9 +1,6 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - -describe("Service Commands", function() { +describe("Link/Unlink Commands", function() { before(startMaxScale) it('link servers to a service', function() { diff --git a/maxctrl/test/rotate.js b/maxctrl/test/rotate.js new file mode 100644 index 000000000..63a32f7a8 --- /dev/null +++ b/maxctrl/test/rotate.js @@ -0,0 +1,12 @@ +require('../test_utils.js')() + +describe("Rotate Commands", function() { + before(startMaxScale) + + it('rotate logs', function() { + return doCommand('rotate logs') + .should.be.fulfilled + }); + + after(stopMaxScale) +}); diff --git a/maxctrl/test/special.js b/maxctrl/test/special.js new file mode 100644 index 000000000..6fc45ab6a --- /dev/null +++ b/maxctrl/test/special.js @@ -0,0 +1,20 @@ +require('../test_utils.js')() + +describe("Library invocation", function() { + before(startMaxScale) + + var ctrl = require('../lib/core.js') + var opts = { extra_args: [ '--quiet'] } + + it('extra options', function() { + return ctrl.execute('list servers'.split(' '), opts) + .should.be.fulfilled + }) + + it('no options', function() { + return ctrl.execute('list servers'.split(' ')) + .should.be.fulfilled + }) + + after(stopMaxScale) +}); diff --git a/maxctrl/test/startstop.js b/maxctrl/test/startstop.js index 7f2e4825e..fd58391a4 100644 --- a/maxctrl/test/startstop.js +++ b/maxctrl/test/startstop.js @@ -1,8 +1,5 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - describe("Start/Stop Commands", function() { before(startMaxScale) diff --git a/maxctrl/test/states.js b/maxctrl/test/states.js index 29ae81e30..6f3ebdd40 100644 --- a/maxctrl/test/states.js +++ b/maxctrl/test/states.js @@ -1,9 +1,6 @@ require('../test_utils.js')() -var ctrl = require('../lib/core.js') -var opts = { extra_args: [ '--quiet'] } - -describe("Server states", function() { +describe("Set/Clear Commands", function() { before(function() { return startMaxScale() .then(function() { diff --git a/maxctrl/test/unknown.js b/maxctrl/test/unknown.js index 18d513290..edcf8d893 100644 --- a/maxctrl/test/unknown.js +++ b/maxctrl/test/unknown.js @@ -6,6 +6,8 @@ describe("Unknown Commands", function() { var endpoints = [ 'list', 'show', + 'set', + 'clear', 'enable', 'disable', 'create', @@ -26,5 +28,10 @@ describe("Unknown Commands", function() { }) }) + it('generic unknown command', function() { + return doCommand('something') + .should.be.rejected + }) + after(stopMaxScale) });