Fix unhandled promise rejection in create monitor

If a monitor was created with an argument that was not a key-value type, a
promise would be rejected outside of the main maxctrl function. Added a
test case that covers this and fixed a few other test coverage problems
that were present.
This commit is contained in:
Markus Mäkelä 2019-04-17 00:00:24 +03:00
parent cba23781e0
commit 163b3a2da5
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
4 changed files with 30 additions and 6 deletions

View File

@ -159,12 +159,10 @@ exports.builder = function(yargs) {
}
}
if (argv.params) {
var err = validateParams(argv, argv.params)
if (err) {
return Promise.reject(err)
}
var err = false;
if (argv.params) {
err = validateParams(argv, argv.params)
monitor.data.attributes.parameters = argv.params.reduce(to_obj, {})
}
@ -182,6 +180,9 @@ exports.builder = function(yargs) {
}
maxctrl(argv, function(host) {
if (err) {
return Promise.reject(err)
}
return doRequest(host, 'monitors', null, {method: 'POST', body: monitor})
})
})

View File

@ -18,6 +18,18 @@ describe("Create/Destroy Commands", function() {
.should.be.rejected
})
it('monitor without parameters fails due to missing user parameter', function() {
return verifyCommand('create monitor my-monitor mysqlmon', 'monitors/my-monitor')
.should.be.rejected
})
it('destroy monitor created without parameters', function() {
return doCommand('destroy monitor my-monitor')
.should.be.fulfilled
.then(() => doCommand('show monitor my-monitor'))
.should.be.rejected
})
it('will not destroy the same monitor again', function() {
return doCommand('destroy monitor my-monitor')
.should.be.rejected
@ -38,6 +50,11 @@ describe("Create/Destroy Commands", function() {
.should.be.rejected
})
it('will not create monitor with malformed parameters', function() {
return doCommand('create monitor my-monitor mariadbmon not-a-param')
.should.be.rejected
})
it('create monitor with options', function() {
return doCommand('unlink monitor MariaDB-Monitor server4')
.then(() => verifyCommand('create monitor my-monitor mysqlmon --servers server4 --monitor-user maxuser --monitor-password maxpwd',

View File

@ -15,5 +15,10 @@ describe("Draining servers", function() {
.should.eventually.have.string("Maintenance")
})
it('does not drain non-existent server', function() {
return doCommand('drain server not-a-server')
.should.be.rejected
})
after(stopMaxScale)
});

View File

@ -19,7 +19,8 @@ describe("Unknown Commands", function() {
'alter',
'rotate',
'call',
'cluster'
'cluster',
'drain'
]
endpoints.forEach(function (i) {