MXS-1300: Reorganize and refactor tests

The tests are now sorted by command type. This allows for more consistent
test creation as tests can be done per source code file instead of per
object type.

Added helper functions for common testing operations. The two main ones
are doCommand, which executes a MaxCtrl command and returns a result, and
verifyCommand, that executes a command and verifies the result via the
REST API.
This commit is contained in:
Markus Mäkelä
2017-07-22 01:57:00 +03:00
parent 03b00c7746
commit e76dc80e47
12 changed files with 381 additions and 279 deletions

89
maxctrl/test/alter.js Normal file
View File

@ -0,0 +1,89 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Alter Commands", function() {
before(startMaxScale)
it('alter server', function() {
return verifyCommand('alter server server1 port 3004', 'servers/server1')
.then(function(res) {
res.data.attributes.parameters.port.should.equal(3004)
})
})
it('alter server with bad parameters', function() {
return doCommand('alter server server1 port not-a-port')
.should.be.rejected
})
it('alter nonexistent server', function() {
return doCommand('alter server server123 port 3000')
.should.be.rejected
})
it('alter monitor', function() {
return verifyCommand('alter monitor MySQL-Monitor monitor_interval 1000', 'monitors/MySQL-Monitor')
.then(function(res) {
res.data.attributes.parameters.monitor_interval.should.equal(1000)
})
})
it('alter monitor with bad parameters', function() {
return doCommand('alter monitor MySQL-Monitor monitor_interval not-a-number')
.should.be.rejected
})
it('alter nonexistent monitor', function() {
return doCommand('alter monitor monitor123 monitor_interval 3000')
.should.be.rejected
})
it('alter service parameter', function() {
return verifyCommand('alter service Read-Connection-Router user testuser', 'services/Read-Connection-Router')
.then(function(res) {
res.data.attributes.parameters.user.should.equal("testuser")
})
})
it('alter non-existent service parameter', function() {
return doCommand('alter service Read-Connection-Router turbocharge yes-please')
.should.be.rejected
})
it('alter non-existent service', function() {
return doCommand('alter service not-a-service user maxuser')
.should.be.rejected
})
it('alter logging', function() {
return verifyCommand('alter logging maxlog false', 'maxscale/logs')
.then(function() {
return verifyCommand('alter logging syslog false', 'maxscale/logs')
})
.then(function(res) {
res.data.attributes.parameters.maxlog.should.equal(false)
res.data.attributes.parameters.syslog.should.equal(false)
})
})
it('alter logging with bad parameter', function() {
doCommand('alter logging some-parameter maybe')
.should.be.rejectted
})
it('alter maxscale', function() {
return verifyCommand('alter maxscale auth_connect_timeout 5', 'maxscale')
.then(function(res) {
res.data.attributes.parameters.auth_connect_timeout.should.equal(5)
})
})
it('alter maxscale with bad parameter', function() {
return doCommand('alter maxscale some_timeout 123')
.should.be.rejected
})
after(stopMaxScale)
});