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.
This commit is contained in:
Markus Mäkelä 2017-07-22 02:53:39 +03:00
parent 090de1a0f7
commit c9f3d014d6
11 changed files with 109 additions and 27 deletions

View File

@ -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) {

View File

@ -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)

View File

@ -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)
});

View File

@ -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) {

View File

@ -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)
});

View File

@ -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() {

12
maxctrl/test/rotate.js Normal file
View File

@ -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)
});

20
maxctrl/test/special.js Normal file
View File

@ -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)
});

View File

@ -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)

View File

@ -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() {

View File

@ -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)
});