Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 37 additions & 59 deletions test/functional/CommandCallFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,60 @@
/* eslint-env mocha */

const { expect } = require('chai');
const { readFileSync } = require('fs');
const { parseString } = require('xml2js');
const { CommandCall } = require('../../lib/itoolkit');
const { returnTransports } = require('../../lib/utils');
const { CommandCall, Connection } = require('../../lib/itoolkit');
const { config, printConfig } = require('./config');

// Set Env variables or set values here.
let privateKey;
if (process.env.TKPK) {
privateKey = readFileSync(process.env.TKPK, 'utf-8');
}
const opt = {
database: process.env.TKDB || '*LOCAL',
username: process.env.TKUSER || '',
password: process.env.TKPASS || '',
host: process.env.TKHOST || 'localhost',
port: process.env.TKPORT,
path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm',
privateKey,
passphrase: process.env.TKPHRASE,
verbose: !!process.env.TKVERBOSE,
dsn: process.env.TKDSN,
};

const transports = returnTransports(opt);

describe('CommandCall Functional Tests', () => {
before(() => {
printConfig();
});

describe('CL command tests', () => {
transports.forEach((transport) => {
it(`calls CL command using ${transport.name} transport`, (done) => {
const connection = transport.me;
connection.add(new CommandCall({ command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)', type: 'cl' }));
connection.run((error, xmlOut) => {
expect(error).to.equal(null);
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.cmd[0].success[0]).to.include('+++ success RTVJOBA USRLIBL(?) SYSLIBL(?)');
done();
});
it('calls CL command', (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);
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.cmd[0].success[0]).to.include('+++ success RTVJOBA USRLIBL(?) SYSLIBL(?)');
done();
});
});
});
});

describe('SH command tests', () => {
transports.forEach((transport) => {
it(`calls PASE shell command using ${transport.name} transport`, (done) => {
const connection = transport.me;
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
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.sh[0]._).to.match(/(System\sStatus\sInformation)/);
done();
});
it('calls PASE shell command', (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
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.sh[0]._).to.match(/(System\sStatus\sInformation)/);
done();
});
});
});
});

describe('QSH command tests', () => {
transports.forEach((transport) => {
it(`calls QSH command using ${transport.name} transport`, (done) => {
const connection = transport.me;
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
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/);
done();
});
it('calls QSH command', (done) => {
const connection = new Connection(config);
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
parseString(xmlOut, (parseError, result) => {
expect(parseError).to.equal(null);
expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/);
done();
});
});
});
Expand Down
Loading