From ccdf1c56791eaae60d7a13495935242cf77a1040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 9 Aug 2018 11:16:24 +0300 Subject: [PATCH] Improve MaxCtrl test coverage Added tests that cover areas that weren't tested before. --- maxctrl/test/api.js | 51 +++++++++++++++++++++++++++++++++++++++++++ maxctrl/test/drain.js | 19 ++++++++++++++++ maxctrl/test_utils.js | 8 +++++++ 3 files changed, 78 insertions(+) create mode 100644 maxctrl/test/api.js create mode 100644 maxctrl/test/drain.js diff --git a/maxctrl/test/api.js b/maxctrl/test/api.js new file mode 100644 index 000000000..f6134c1ea --- /dev/null +++ b/maxctrl/test/api.js @@ -0,0 +1,51 @@ +require('../test_utils.js')() + +describe("API", function() { + before(startMaxScale) + + it('gets resource', function() { + return doCommand('api get servers') + .should.be.fulfilled + }) + + it('gets resource with path', function() { + return doCommand('api get servers data[0].id') + .then((res) => { + js = JSON.parse(res) + js.should.equal("server1") + }) + }) + + it('sums integer values', function() { + return doCommand('api get servers data[].attributes.statistics.connections --sum') + .then((res) => { + js = JSON.parse(res) + js.should.equal(0) + }) + }) + + it('does not sum string values', function() { + return doCommand('api get servers data[].id --sum') + .then((res) => { + js = JSON.parse(res) + js.should.deep.equal(["server1", "server2", "server3", "server4"]) + }) + }) + + it('does not sum objects', function() { + return doCommand('api get servers --sum') + .should.be.fulfilled + }) + + it('does not sum undefined objects', function() { + return doCommand('api get servers asdf --sum') + .should.be.fulfilled + }) + + it('ignores unknown command', function() { + return doCommand('api upgrade') + .should.be.rejected + }) + + after(stopMaxScale) +}); diff --git a/maxctrl/test/drain.js b/maxctrl/test/drain.js new file mode 100644 index 000000000..b4d5f6673 --- /dev/null +++ b/maxctrl/test/drain.js @@ -0,0 +1,19 @@ +require('../test_utils.js')() + +describe("Draining servers", function() { + before(startMaxScale) + + it('drains server', function() { + return doCommand('drain server server1') + .should.be.fulfilled + }) + + it('checks server is in maintenance', function() { + // The maintenance state isn't set instantly + return sleepFor(2000) + .then(() => doCommand('api get servers/server1 data.attributes.state')) + .should.eventually.have.string("Maintenance") + }) + + after(stopMaxScale) +}); diff --git a/maxctrl/test_utils.js b/maxctrl/test_utils.js index 0cf145ecc..6bfdecc66 100644 --- a/maxctrl/test_utils.js +++ b/maxctrl/test_utils.js @@ -88,4 +88,12 @@ module.exports = function() { return request.get(host + resource, {json: true}) }) }; + + this.sleepFor = function(time) { + return new Promise((resolve, reject) => { + var timer = setInterval(() => { + resolve() + }, time) + }) + } }