-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fall back to ssh_options[:user] if host.user.nil?
Up until now Airbrussh has displayed the username using `host.name`. However, this may be `nil` in favor of using `ssh_options[:user]`. Use the SSH options in this case. If for some reason no user is specified with either method, then omit the `@` symbol and just print the hostname instead of `@hostname`. Addresses #65.
- Loading branch information
1 parent
0ff3244
commit 4095b6f
Showing
3 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,16 @@ | |
|
||
class Airbrussh::CommandFormatterTest < Minitest::Test | ||
def setup | ||
sshkit_command = OpenStruct.new( | ||
:host => "12.34.56.78", | ||
:user => "deployer", | ||
@sshkit_command = OpenStruct.new( | ||
:host => host("deployer", "12.34.56.78"), | ||
:options => { :user => "override" }, | ||
:runtime => 1.23456, | ||
:failure? => false | ||
) | ||
def sshkit_command.to_s | ||
def @sshkit_command.to_s | ||
"/usr/bin/env echo hello" | ||
end | ||
@command = Airbrussh::CommandFormatter.new(sshkit_command, 0) | ||
@command = Airbrussh::CommandFormatter.new(@sshkit_command, 0) | ||
end | ||
|
||
def test_format_output | ||
|
@@ -39,4 +39,28 @@ def test_exit_message_failure | |
@command.exit_message("out.log")) | ||
end | ||
end | ||
|
||
def test_uses_ssh_options_if_host_user_is_absent | ||
@sshkit_command.host = host(nil, "12.34.56.78", :user => "sshuser") | ||
assert_equal( | ||
"\e[0;32;49m✔ 01 [email protected]\e[0m \e[0;90;49m1.235s\e[0m", | ||
@command.exit_message) | ||
end | ||
|
||
def test_shows_hostname_only_if_no_user | ||
@sshkit_command.host = host(nil, "12.34.56.78") | ||
assert_equal( | ||
"\e[0;32;49m✔ 01 12.34.56.78\e[0m \e[0;90;49m1.235s\e[0m", | ||
@command.exit_message) | ||
end | ||
|
||
private | ||
|
||
def host(user, hostname, ssh_options={}) | ||
SSHKit::Host.new( | ||
:user => user, | ||
:hostname => hostname, | ||
:ssh_options => ssh_options | ||
) | ||
end | ||
end |