smartssh/test/test.ts

76 lines
3.1 KiB
TypeScript
Raw Normal View History

2016-11-23 11:38:38 +00:00
import 'typings-test'
import * as should from 'should'
import smartssh = require('../dist/index')
import path = require('path')
describe('smartssh',function(){
let testSshInstance: smartssh.SshInstance
let testSshKey: smartssh.SshKey
describe('.SshKey',function(){
it("'new' keyword should create a valid SshKey object",function(){
testSshKey = new smartssh.SshKey({
2016-11-23 11:38:38 +00:00
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
})
should(testSshKey).be.instanceof(smartssh.SshKey)
})
it('.type should be a valid type',function(){
should(testSshKey.type).equal('duplex')
})
it('.publicKey should be public key',function(){
should(testSshKey.pubKey).equal('someExamplePublicKey')
})
it('.privateKey should be private key',function(){
should(testSshKey.privKey).equal('someExamplePrivateKey')
})
it('.publicKeyBase64 should be public key base 64 encoded',function(){
testSshKey.pubKeyBase64
})
it('.store() should store the file to disk',function(){
testSshKey.store(path.join(process.cwd(),'test/temp'))
})
})
describe('.SshInstance',function(){
2016-06-01 02:18:31 +00:00
it("'new' keyword should create a new SshInstance object from class",function(){
2016-06-26 14:16:12 +00:00
testSshInstance = new smartssh.SshInstance({
2016-11-23 11:38:38 +00:00
sshDirPath: path.join(process.cwd(),'test/temp/')
})
should(testSshInstance).be.instanceof(smartssh.SshInstance)
})
it('.addKey() should accept a new SshKey object',function(){
2016-06-01 00:48:38 +00:00
testSshInstance.addKey(new smartssh.SshKey({
2016-11-23 11:38:38 +00:00
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'gitlab.com'
}))
2016-06-01 00:48:38 +00:00
testSshInstance.addKey(new smartssh.SshKey({
2016-11-23 11:38:38 +00:00
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'bitbucket.org'
}))
2016-06-01 00:48:38 +00:00
testSshInstance.addKey(new smartssh.SshKey({
2016-11-23 11:38:38 +00:00
public: 'someGitHubPublicKey',
private: 'someGitHubPrivateKey',
host: 'github.com'
}))
})
it('.sshKeys should point to an array of sshKeys',function(){
let sshKeyArray = testSshInstance.sshKeys
should(sshKeyArray).be.Array()
should(sshKeyArray[0].host).equal('gitlab.com')
should(sshKeyArray[1].host).equal('bitbucket.org')
should(sshKeyArray[2].host).equal('github.com')
})
it('.getKey() should get a specific key selected by host',function(){
should(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey')
})
it('.removeKey() should remove a key',function(){
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'))
should(testSshInstance.sshKeys[1].host).equal('github.com')
2016-06-01 02:18:31 +00:00
})
2016-11-23 11:38:38 +00:00
it('it should store to disk',function(){
testSshInstance.writeToDisk()
2016-06-01 02:18:31 +00:00
})
2016-11-23 11:38:38 +00:00
})
})