From 625e3f5a27c20fff5a7ed025fc8f57eba39633cf Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Mon, 20 Jul 2020 14:13:53 -0500 Subject: [PATCH 1/3] test: Check the XMLSERVICE version for QSH support --- test/functional/CommandCallFunctional.js | 13 ++++++++++++- test/functional/checkVersion.js | 16 ++++++++++++++++ test/functional/deprecated/commandsFunctional.js | 13 ++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/functional/checkVersion.js diff --git a/test/functional/CommandCallFunctional.js b/test/functional/CommandCallFunctional.js index 0a19d3fb..a62d4d96 100644 --- a/test/functional/CommandCallFunctional.js +++ b/test/functional/CommandCallFunctional.js @@ -17,8 +17,9 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); -const { CommandCall, Connection } = require('../../lib/itoolkit'); +const { CommandCall, Connection, ProgramCall } = require('../../lib/itoolkit'); const { config, printConfig } = require('./config'); +const { isQSHSupported } = require('./checkVersion'); describe('CommandCall Functional Tests', function () { @@ -61,6 +62,7 @@ describe('CommandCall Functional Tests', function () { describe('QSH command tests', function () { it('calls QSH command', function (done) { const connection = new Connection(config); + connection.add(new ProgramCall('MYPGMTOOLONG')); connection.add(new CommandCall({ command: 'system wrksyssts', type: 'qsh' })); connection.run((error, xmlOut) => { expect(error).to.equal(null); @@ -68,6 +70,15 @@ describe('CommandCall Functional Tests', function () { // but on error sh or qsh node will not have any inner data parseString(xmlOut, (parseError, result) => { expect(parseError).to.equal(null); + const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/); + if (!match) { + throw Error('Unable to determine XMLSERVICE version'); + } + if (!isQSHSupported(match[0])) { + // skip if QSH is unsupported + console.log(`XMLSERVICE version ${match[0]} does not support QSH`); + this.skip(); + } expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/); done(); }); diff --git a/test/functional/checkVersion.js b/test/functional/checkVersion.js new file mode 100644 index 00000000..2a23b790 --- /dev/null +++ b/test/functional/checkVersion.js @@ -0,0 +1,16 @@ +/** + * Checks if XMLSERVICE version supports QSH. + * XMLSERVICE >= 1.9.8 supports QSH + * @param {string} version - expects sematic version i.e. 1.2.3 + */ +function isQSHSupported(version) { + const semver = version.split('.'); + if (semver[0] == 1 && semver[1] < 9) { + return false; + } else if (semver[0] == 1 && semver[1] == 9 && semver[2] < 8) { + return false + } + return true; +} + +module.exports.isQSHSupported = isQSHSupported; diff --git a/test/functional/deprecated/commandsFunctional.js b/test/functional/deprecated/commandsFunctional.js index 36e8815d..530a4e19 100644 --- a/test/functional/deprecated/commandsFunctional.js +++ b/test/functional/deprecated/commandsFunctional.js @@ -20,10 +20,11 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); const { - iCmd, iSh, iQsh, iConn, + iCmd, iSh, iQsh, iConn, iPgm } = require('../../../lib/itoolkit'); const { config, printConfig } = require('../config'); +const { isQSHSupported } = require('../checkVersion'); // deprecated tests are in place to test compatability using deprecated classes and functions // these tests use deprecated iConn Class to create a connnection @@ -82,12 +83,22 @@ describe('iSh, iCmd, iQsh, Functional Tests', function () { describe('iQsh()', function () { it('calls QSH command', function (done) { const connection = new iConn(database, username, password, restOptions); + connection.add(new iPgm('MYPGMTOOLONG')); connection.add(iQsh('system wrksyssts')); connection.run((xmlOut) => { // xs does not return success property for sh or qsh command calls // but on error sh or qsh node will not have any inner data parseString(xmlOut, (parseError, result) => { expect(parseError).to.equal(null); + const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/); + if (!match) { + throw Error('Unable to determine XMLSERVICE version'); + } + if (!isQSHSupported(match[0])) { + // skip if QSH is unsupported + console.log(`XMLSERVICE version ${match[0]} does not support QSH`); + this.skip(); + } expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/); done(); }); From 1b6d02af9cce4c8721b4176442c5bda3213bbe2c Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:22:03 -0500 Subject: [PATCH 2/3] fixup! test: Check the XMLSERVICE version for QSH support --- test/functional/checkVersion.js | 8 ++++---- test/functional/deprecated/commandsFunctional.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/functional/checkVersion.js b/test/functional/checkVersion.js index 2a23b790..273a077f 100644 --- a/test/functional/checkVersion.js +++ b/test/functional/checkVersion.js @@ -1,14 +1,14 @@ /** - * Checks if XMLSERVICE version supports QSH. + * Checks if XMLSERVICE version supports QSH. * XMLSERVICE >= 1.9.8 supports QSH * @param {string} version - expects sematic version i.e. 1.2.3 */ function isQSHSupported(version) { const semver = version.split('.'); - if (semver[0] == 1 && semver[1] < 9) { + if (semver[0] === 1 && semver[1] < 9) { + return false; + } if (semver[0] === 1 && semver[1] === 9 && semver[2] < 8) { return false; - } else if (semver[0] == 1 && semver[1] == 9 && semver[2] < 8) { - return false } return true; } diff --git a/test/functional/deprecated/commandsFunctional.js b/test/functional/deprecated/commandsFunctional.js index 530a4e19..cfe65977 100644 --- a/test/functional/deprecated/commandsFunctional.js +++ b/test/functional/deprecated/commandsFunctional.js @@ -20,7 +20,7 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); const { - iCmd, iSh, iQsh, iConn, iPgm + iCmd, iSh, iQsh, iConn, iPgm, } = require('../../../lib/itoolkit'); const { config, printConfig } = require('../config'); From 1e4f5864e383c9e7045ce120c7335dc0177c5dd7 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:39:21 -0500 Subject: [PATCH 3/3] fixup! fixup! test: Check the XMLSERVICE version for QSH support --- test/functional/checkVersion.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/checkVersion.js b/test/functional/checkVersion.js index 273a077f..692403dd 100644 --- a/test/functional/checkVersion.js +++ b/test/functional/checkVersion.js @@ -4,7 +4,8 @@ * @param {string} version - expects sematic version i.e. 1.2.3 */ function isQSHSupported(version) { - const semver = version.split('.'); + // maps array of strings to numbers i.e. ['1', '2', '3'] -> [1, 2, 3] + const semver = version.split('.').map(Number); if (semver[0] === 1 && semver[1] < 9) { return false; } if (semver[0] === 1 && semver[1] === 9 && semver[2] < 8) {