Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Fix SSH command with port.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Aug 14, 2015
1 parent 77adea7 commit 2d16bd6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### 0.1.2-pre
*
* Fix SSH command with port

### 0.1.1
* Add build reports to readme
Expand Down
6 changes: 3 additions & 3 deletions lib/breaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ Breaker.prototype.format = function (type, cb) {
Breaker.prototype.ssh = function (command, cb) {
var tasks = [];
this._config().forEach(function (item) {

console.log('+ %s', item.host);
if (!item.ssh) {
item.ssh = [{}];
}
item.ssh.forEach(function (sshItem) {
tasks.push(function (cb) {
var sshCommand = util.format('ssh %s %s%s%s %s',
var sshCommand = util.format('ssh %s %s %s%s %s',
(sshItem.key) ? '-i ' + sshItem.key : '',
((sshItem.port) ? '-p ' + sshItem.port : ''),
(sshItem.user) ? sshItem.user + '@' : '',
item.host,
((sshItem.port) ? ':' + sshItem.port : ''),
'\'' + command + '\''
);
console.log('> ' + sshCommand);
Expand Down
24 changes: 12 additions & 12 deletions test/breaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ buster.testCase('breaker - ssh', {
this.mockConsole = this.mock(console);
},
'should exec ssh command to hosts': function (done) {
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa1 user1@dev1.com:22 \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa2 user2@dev2.com:22 \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa3 user3@dev3.com:22 \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa1 -p 22 user1@dev1.com \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa2 -p 22 user2@dev2.com \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa3 -p 22 user3@dev3.com \'df -kh;\'', true).callsArgWith(2);
this.mockConsole.expects('log').once().withExactArgs('+ %s', 'dev1.com');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa1 user1@dev1.com:22 \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa1 -p 22 user1@dev1.com \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('+ %s', 'dev2.com');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa2 user2@dev2.com:22 \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa2 -p 22 user2@dev2.com \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('+ %s', 'dev3.com');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa3 user3@dev3.com:22 \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa3 -p 22 user3@dev3.com \'df -kh;\'');
var breaker = new Breaker();
breaker._config = function () {
return [
Expand All @@ -69,11 +69,11 @@ buster.testCase('breaker - ssh', {
});
},
'should exec multiple ssh settings with same command on same host': function (done) {
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa1 user1@dev1.com:22 \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa2 user2@dev1.com:2222 \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa1 -p 22 user1@dev1.com \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh -i id_rsa2 -p 2222 user2@dev1.com \'df -kh;\'', true).callsArgWith(2);
this.mockConsole.expects('log').once().withExactArgs('+ %s', 'dev1.com');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa1 user1@dev1.com:22 \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa2 user2@dev1.com:2222 \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa1 -p 22 user1@dev1.com \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh -i id_rsa2 -p 2222 user2@dev1.com \'df -kh;\'');
var breaker = new Breaker();
breaker._config = function () {
return [
Expand All @@ -86,9 +86,9 @@ buster.testCase('breaker - ssh', {
});
},
'should create ssh command without key, with default user, and no port': function (done) {
this.mockBag.expects('exec').once().withArgs('ssh dev1.com \'df -kh;\'', true).callsArgWith(2);
this.mockBag.expects('exec').once().withArgs('ssh dev1.com \'df -kh;\'', true).callsArgWith(2);
this.mockConsole.expects('log').once().withExactArgs('+ %s', 'dev1.com');
this.mockConsole.expects('log').once().withExactArgs('> ssh dev1.com \'df -kh;\'');
this.mockConsole.expects('log').once().withExactArgs('> ssh dev1.com \'df -kh;\'');
var breaker = new Breaker();
breaker._config = function () {
return [
Expand Down

0 comments on commit 2d16bd6

Please sign in to comment.