import Ssh from '../src/ssh' import to from 'await-to-js' import { expect } from 'chai' import { it } from 'mocha' import logger from '@uci/logger' describe('SSH Class Testing ',async ()=> { let remote let log before(async () => { log = logger({ name: 'remote-code', test:'/test/ssh.test.js', class:'Ssh', file:'src/ssh.js', id: 'testing' }) remote = new Ssh() await remote.configure('./test/config/ssh') // will pick up config file format log.info(`making connection to ${remote.opts.host}`) let [err] = await to(remote.connect()) if (err) { log.info('unable to connect aborting test', err) throw new Error (err) } log.info('ready for testing') }) after(async () => { remote.close() }) it('simple connect and execute "cd /opt && pwd" on remote' , async function () { let [err,res] = await to(remote.exec('cd /opt && pwd')) if (err) { log.info('error running command aborting test', err) return } log.info({remoteHost:remote.opts.host, reply:res.reply.toString().trim(), err:err, cmd:res.command, msg:`remote command completed ${res.command}`}) expect(res.reply.toString().trim(), 'test failed').to.equal('/opt') }) it('connect via an "interactive shell" and cat the test.txt file in home directory"' , async function () { let [err,res] = await to(remote.shell('cat test.txt')) // cd /opt && pwd if (err) { log.info('error running shell command aborting test', err) throw new Error(err) } let passed = false if (res.reply.indexOf('47fciogjei439djfjla') > 0) passed=true log.info({remoteHost:remote.opts.host, reply:res.reply.toString().trim(), err:err, cmd:res.command, msg:`remote command completed ${res.command}`}) expect(passed, 'test failed').to.equal(true) }) }) // function hooks(remote) { // // // beforeEach(async() => { // // await someasyncfunctiontodobeforeeachtest() // // }) // // // after(async() => { // // await someasyncfunctiontodoaftereeachtest() // // }) // // }