-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCommandCallFunctional.js
90 lines (81 loc) · 3.22 KB
/
CommandCallFunctional.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright contributors to the nodejs-itoolkit project
// SPDX-License-Identifier: MIT
const { expect } = require('chai');
const { XMLParser, XMLValidator } = require('fast-xml-parser');
const { CommandCall, Connection, ProgramCall } = require('../../lib/itoolkit');
const { config, printConfig } = require('./config');
const { isQSHSupported } = require('./checkVersion');
describe('CommandCall Functional Tests', function () {
before(function () {
printConfig();
});
describe('CL command tests', function () {
it('calls CL command', function (done) {
const connection = new Connection(config);
connection.add(new CommandCall({ command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)', type: 'cl' }));
connection.run((error, xmlOut) => {
expect(error).to.equal(null);
const validate = XMLValidator.validate(xmlOut, {
allowBooleanAttributes: true,
});
expect(validate).to.equal(true);
const parser = new XMLParser();
const result = parser.parse(xmlOut);
expect(result.myscript.cmd.success).to.include('+++ success RTVJOBA USRLIBL(?) SYSLIBL(?)');
done();
});
});
});
describe('SH command tests', function () {
it('calls PASE shell command', function (done) {
const connection = new Connection(config);
connection.add(new CommandCall({ command: 'system -i wrksyssts', type: 'sh' }));
connection.run((error, xmlOut) => {
expect(error).to.equal(null);
// 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
const validate = XMLValidator.validate(xmlOut, {
allowBooleanAttributes: true,
});
expect(validate).to.equal(true);
const parser = new XMLParser();
const result = parser.parse(xmlOut);
expect(result.myscript.sh).to.match(/(System\sStatus\sInformation)/);
done();
});
});
});
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);
// 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
const validate = XMLValidator.validate(xmlOut, {
allowBooleanAttributes: true,
});
expect(validate).to.equal(true);
const parser = new XMLParser();
const result = parser.parse(xmlOut);
const { version } = result.myscript.pgm;
const match = version.match(/\d\.\d\.\d/);
if (!match) {
done(new Error('Unable to determine XMLSERVICE version'));
return;
}
if (!isQSHSupported(match[0])) {
console.log(`XMLSERVICE version ${match[0]} does not support QSH`);
this.skip();
done();
return;
}
const qshContent = result.myscript.qsh;
expect(qshContent).to.match(/(System\sStatus\sInformation)/);
done();
});
});
});
});