diff --git a/maxctrl/CMakeLists.txt b/maxctrl/CMakeLists.txt index e0f6eaecd..5601c3d5b 100644 --- a/maxctrl/CMakeLists.txt +++ b/maxctrl/CMakeLists.txt @@ -6,6 +6,14 @@ if (NPM_FOUND) WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_custom_target(maxctrl ALL DEPENDS ${CMAKE_BINARY_DIR}/maxctrl/maxctrl) install_script(${CMAKE_BINARY_DIR}/maxctrl/maxctrl core) + + add_custom_target(test_maxctrl + COMMAND ${CMAKE_SOURCE_DIR}/test/run_npm_test.sh + ${CMAKE_SOURCE_DIR} # Path to MaxScale sources + ${CMAKE_CURRENT_SOURCE_DIR} # Path to test sources + ${CMAKE_BINARY_DIR}/maxctrl-test/ # Location where tests are built and run + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + else() message(STATUS "Not building MaxCtrl: npm not found") endif() diff --git a/maxctrl/package.json b/maxctrl/package.json index 247c7d073..bf8b3a1c0 100644 --- a/maxctrl/package.json +++ b/maxctrl/package.json @@ -5,7 +5,7 @@ "repository": "https://github.com/mariadb-corporation/MaxScale", "main": "maxctrl.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha --timeout 30000 --slow 10000" }, "keywords": [ "maxscale" @@ -22,5 +22,10 @@ "request": "^2.81.0", "request-promise-native": "^1.0.3", "yargs": "^8.0.2" + }, + "devDependencies": { + "chai": "^3.5.0", + "chai-as-promised": "^6.0.0", + "mocha": "^3.3.0" } } diff --git a/maxctrl/test/diagnostics.js b/maxctrl/test/diagnostics.js new file mode 100644 index 000000000..21cbf65d2 --- /dev/null +++ b/maxctrl/test/diagnostics.js @@ -0,0 +1,35 @@ +require('../test_utils.js')() + +describe("Diagnostic commands", function() { + before(startMaxScale) + + var ctrl = require('../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', + ] + + tests.forEach(function(i) { + it(i, function() { + return ctrl.execute(i.split(' '), { + extra_args: [ '--quiet'] + }) + .should.be.fulfilled + }); + }) + + after(stopMaxScale) +}); diff --git a/maxctrl/test_utils.js b/maxctrl/test_utils.js new file mode 100644 index 000000000..aca8ee661 --- /dev/null +++ b/maxctrl/test_utils.js @@ -0,0 +1,26 @@ +var child_process = require("child_process") + +module.exports = function() { + this.request = require("request-promise-native") + this.chai = require("chai") + this.assert = require("assert") + this.chaiAsPromised = require("chai-as-promised") + chai.use(chaiAsPromised) + this.should = chai.should() + this.expect = chai.expect + + this.startMaxScale = function(done) { + child_process.execFile("./start_maxscale.sh", function(err, stdout, stderr) { + if (process.env.MAXSCALE_DIR == null) { + throw new Error("MAXSCALE_DIR is not set"); + } + + done() + }) + }; + this.stopMaxScale = function(done) { + child_process.execFile("./stop_maxscale.sh", function(err, stdout, stderr) { + done() + }) + }; +} diff --git a/test/stop_maxscale.sh b/test/stop_maxscale.sh index 2933b88ba..b948c5b57 100755 --- a/test/stop_maxscale.sh +++ b/test/stop_maxscale.sh @@ -21,7 +21,7 @@ pkill -9 '^maxscale$' rm -r $maxscaledir/lib/maxscale rm -r $maxscaledir/cache/maxscale rm -r $maxscaledir/run/maxscale -rm /tmp/maxadmin.sock +test -f /tmp/maxadmin.sock && rm /tmp/maxadmin.sock mkdir -m 0755 -p $maxscaledir/lib/maxscale mkdir -m 0755 -p $maxscaledir/cache/maxscale