Skip to content

Commit 9067616

Browse files
authored
test: Check the XMLSERVICE version for QSH support (#303)
1 parent 515bc77 commit 9067616

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

test/functional/CommandCallFunctional.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
const { expect } = require('chai');
1919
const { parseString } = require('xml2js');
20-
const { CommandCall, Connection } = require('../../lib/itoolkit');
20+
const { CommandCall, Connection, ProgramCall } = require('../../lib/itoolkit');
2121
const { config, printConfig } = require('./config');
22+
const { isQSHSupported } = require('./checkVersion');
2223

2324

2425
describe('CommandCall Functional Tests', function () {
@@ -61,13 +62,23 @@ describe('CommandCall Functional Tests', function () {
6162
describe('QSH command tests', function () {
6263
it('calls QSH command', function (done) {
6364
const connection = new Connection(config);
65+
connection.add(new ProgramCall('MYPGMTOOLONG'));
6466
connection.add(new CommandCall({ command: 'system wrksyssts', type: 'qsh' }));
6567
connection.run((error, xmlOut) => {
6668
expect(error).to.equal(null);
6769
// xs does not return success property for sh or qsh command calls
6870
// but on error sh or qsh node will not have any inner data
6971
parseString(xmlOut, (parseError, result) => {
7072
expect(parseError).to.equal(null);
73+
const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/);
74+
if (!match) {
75+
throw Error('Unable to determine XMLSERVICE version');
76+
}
77+
if (!isQSHSupported(match[0])) {
78+
// skip if QSH is unsupported
79+
console.log(`XMLSERVICE version ${match[0]} does not support QSH`);
80+
this.skip();
81+
}
7182
expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/);
7283
done();
7384
});

test/functional/checkVersion.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Checks if XMLSERVICE version supports QSH.
3+
* XMLSERVICE >= 1.9.8 supports QSH
4+
* @param {string} version - expects sematic version i.e. 1.2.3
5+
*/
6+
function isQSHSupported(version) {
7+
// maps array of strings to numbers i.e. ['1', '2', '3'] -> [1, 2, 3]
8+
const semver = version.split('.').map(Number);
9+
if (semver[0] === 1 && semver[1] < 9) {
10+
return false;
11+
} if (semver[0] === 1 && semver[1] === 9 && semver[2] < 8) {
12+
return false;
13+
}
14+
return true;
15+
}
16+
17+
module.exports.isQSHSupported = isQSHSupported;

test/functional/deprecated/commandsFunctional.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
const { expect } = require('chai');
2121
const { parseString } = require('xml2js');
2222
const {
23-
iCmd, iSh, iQsh, iConn,
23+
iCmd, iSh, iQsh, iConn, iPgm,
2424
} = require('../../../lib/itoolkit');
2525

2626
const { config, printConfig } = require('../config');
27+
const { isQSHSupported } = require('../checkVersion');
2728

2829
// deprecated tests are in place to test compatability using deprecated classes and functions
2930
// these tests use deprecated iConn Class to create a connnection
@@ -82,12 +83,22 @@ describe('iSh, iCmd, iQsh, Functional Tests', function () {
8283
describe('iQsh()', function () {
8384
it('calls QSH command', function (done) {
8485
const connection = new iConn(database, username, password, restOptions);
86+
connection.add(new iPgm('MYPGMTOOLONG'));
8587
connection.add(iQsh('system wrksyssts'));
8688
connection.run((xmlOut) => {
8789
// xs does not return success property for sh or qsh command calls
8890
// but on error sh or qsh node will not have any inner data
8991
parseString(xmlOut, (parseError, result) => {
9092
expect(parseError).to.equal(null);
93+
const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/);
94+
if (!match) {
95+
throw Error('Unable to determine XMLSERVICE version');
96+
}
97+
if (!isQSHSupported(match[0])) {
98+
// skip if QSH is unsupported
99+
console.log(`XMLSERVICE version ${match[0]} does not support QSH`);
100+
this.skip();
101+
}
91102
expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/);
92103
done();
93104
});

0 commit comments

Comments
 (0)