|
| 1 | +// Copyright (c) International Business Machines Corp. 2019 |
| 2 | +// All Rights Reserved |
| 3 | + |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 5 | +// associated documentation files (the "Software"), to deal in the Software without restriction, |
| 6 | +// including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 7 | +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | + |
| 10 | +// The above copyright notice and this permission notice shall be included in all copies or |
| 11 | +// substantial portions of the Software. |
| 12 | + |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 14 | +// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 15 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 16 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 18 | + |
| 19 | +/* eslint-env mocha */ |
| 20 | + |
| 21 | +const { expect } = require('chai'); |
| 22 | +const { |
| 23 | + iCmd, iSh, iQsh, xmlToJson, |
| 24 | +} = require('../../lib/itoolkit'); |
| 25 | + |
| 26 | +// Set Env variables or set values here. |
| 27 | +const opt = { |
| 28 | + database: process.env.TKDB || '*LOCAL', |
| 29 | + user: process.env.TKUSER || '', |
| 30 | + password: process.env.TKPASS || '', |
| 31 | + host: process.env.TKHOST || 'localhost', |
| 32 | + port: process.env.TKPORT || 80, |
| 33 | + path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm', |
| 34 | +}; |
| 35 | + |
| 36 | +const { returnTransports } = require('../../lib/utils'); |
| 37 | + |
| 38 | +const transports = returnTransports(opt); |
| 39 | + |
| 40 | +describe('iSh, iCmd, iQsh, Functional Tests', () => { |
| 41 | + describe('iCmd()', () => { |
| 42 | + transports.forEach((transport) => { |
| 43 | + it(`calls CL command using ${transport.name} transport`, (done) => { |
| 44 | + const connection = transport.me; |
| 45 | + connection.add(iCmd('RTVJOBA USRLIBL(?) SYSLIBL(?)')); |
| 46 | + connection.run((xmlOut) => { |
| 47 | + const results = xmlToJson(xmlOut); |
| 48 | + results.forEach((result) => { |
| 49 | + expect(result.success).to.equal(true); |
| 50 | + }); |
| 51 | + done(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('iSh()', () => { |
| 58 | + transports.forEach((transport) => { |
| 59 | + it(`calls PASE shell command using ${transport.name} transport`, (done) => { |
| 60 | + const connection = transport.me; |
| 61 | + |
| 62 | + connection.add(iSh('system -i wrksyssts')); |
| 63 | + connection.run((xmlOut) => { |
| 64 | + const results = xmlToJson(xmlOut); |
| 65 | + // xs does not return success property for iSh or iQsh |
| 66 | + // but on error data property = '\n' |
| 67 | + // so lets base success on contents of data. |
| 68 | + results.forEach((result) => { |
| 69 | + expect(result.data).not.to.equal('\n'); |
| 70 | + expect(result.data).to.match(/(System\sStatus\sInformation)/); |
| 71 | + }); |
| 72 | + done(); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe('iQsh()', () => { |
| 79 | + transports.forEach((transport) => { |
| 80 | + it(`calls QSH command using ${transport.name} transport`, (done) => { |
| 81 | + const connection = transport.me; |
| 82 | + connection.add(iQsh('system wrksyssts')); |
| 83 | + connection.run((xmlOut) => { |
| 84 | + const results = xmlToJson(xmlOut); |
| 85 | + // xs does not return success property for iSh or iQsh |
| 86 | + // but on error data property = '\n' |
| 87 | + // so lets base success on contents of data. |
| 88 | + results.forEach((result) => { |
| 89 | + expect(result.data).not.to.equal('\n'); |
| 90 | + expect(result.data).to.match(/(System\sStatus\sInformation)/); |
| 91 | + }); |
| 92 | + done(); |
| 93 | + }); |
| 94 | + }); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments