uci-remote-code/test/ssh.test.js

54 lines
1.4 KiB
JavaScript

import Ssh from '../src/ssh'
import to from 'await-to-js'
import { expect } from 'chai'
import { it } from 'mocha'
import read from 'read-yaml-file'
import logger from '@uci/logger'
// pause = require('@uci/utils').pPause
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' })
let opts = await read('./test/ssh.yaml')
remote = new Ssh(opts)
log.info(`making connection to ${remote.opts.host}`)
let [err] = await to(remote.connect())
if (err) {
log.info('unable to connect aborting test', err)
return err
}
log.info('ready for testing')
})
after(async () => {
remote.close()
})
it('simple connect and reply to "cd /opt && pwd"' , 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(`result of remote command ${res.command} => ${res.reply.toString().trim()}`)
expect(res.reply.toString().trim(), 'test failed').to.equal('/opt')
})
})
// function hooks(remote) {
//
// // beforeEach(async() => {
// // await someasyncfunctiontodobeforeeachtest()
// // })
//
// // after(async() => {
// // await someasyncfunctiontodoaftereeachtest()
// // })
//
// }