Fix some bugs in the SSH tests, replace one error_and_exit with an exception

This commit is contained in:
Mitchell Hashimoto 2010-08-26 23:51:30 -07:00
parent a206d23bc7
commit 500a63c269
5 changed files with 40 additions and 27 deletions

View File

@ -56,6 +56,11 @@ module Vagrant
error_key(:no_env)
end
class SSHUnavailableWindows < VagrantError
status_code(10)
error_key(:ssh_unavailable_windows)
end
class VirtualBoxInvalidOSE < VagrantError
status_code(9)
error_key(:virtualbox_invalid_ose)

View File

@ -22,9 +22,8 @@ module Vagrant
# of options which override the configuration values.
def connect(opts={})
if Mario::Platform.windows?
error_and_exit(:ssh_unavailable_windows,
:key_path => env.config.ssh.private_key_path,
:ssh_port => port(opts))
raise Errors::SSHUnavailableWindows.new(:key_path => env.config.ssh.private_key_path,
:ssh_port => port(opts))
end
options = {}

View File

@ -11,6 +11,21 @@ en:
multi_vm_required: A multi-vm environment is required for name specification to this command.
multi_vm_target_required: `vagrant %{command}` requires a specific VM name to target in a multi-VM environment.
no_env: No Vagrant environment detected. Run `vagrant init` to set one up.
ssh_unavailable_windows: |-
`vagrant ssh` isn't available on the Windows platform. The
vagrant.ppk file for use with Putty is available at:
<%= key_path %>.ppk
To use this create a new Putty session for `vagrant@localhost`
on port `<%= ssh_port %>`, in the Connection>SSH>Auth
configuration section navigate to the vagrant.ppk file,
select it, save the session for later use, and connect.
For a more detailed guide please consult:
http://vagrantup.com/docs/getting-started/windows.
virtualbox_invalid_ose: |-
Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox.
Vagrant currently doesn't support any of the OSE editions due to slight API

View File

@ -153,20 +153,6 @@
Vagrant assumes that this means the command failed!
<%= command %>
:ssh_unavailable_windows: |-
`vagrant ssh` isn't available on the Windows platform. The
vagrant.ppk file is available at
<%= key_path %>.ppk
for use with Putty. To do this create a new Putty session for
`vagrant@localhost` on port `<%= ssh_port %>`, in the Connection>SSH>Auth
configuration section navigate to the vagrant.ppk file,
select it, save the session for later use, and connect.
For a more detailed guide please consult:
http://vagrantup.com/docs/getting-started/windows.html
:system_invalid_class: |-
The specified system does not inherit from `Vagrant::Systems::Base`. The
specified system class must inherit from this class.

View File

@ -68,6 +68,10 @@ class SshTest < Test::Unit::TestCase
Vagrant::Util::Platform.stubs(:leopard?).returns(true)
end
teardown do
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
end
should "fork, exec, and wait" do
pid = mock("pid")
@ssh.expects(:fork).once.returns(pid)
@ -78,18 +82,18 @@ class SshTest < Test::Unit::TestCase
end
context "checking windows" do
teardown do
Mario::Platform.forced = Mario::Platform::Linux
end
should "error and exit if the platform is windows" do
Mario::Platform.expects(:windows?).returns(true)
@ssh.expects(:error_and_exit).with do |error_name, opts|
opts[:key_path] && opts[:ssh_port]
end
@ssh.connect
Mario::Platform.forced = Mario::Platform::Windows7
assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect }
end
should "not error and exit if the platform is anything other that windows" do
Mario::Platform.expects(:windows?).returns(false)
@ssh.expects(:error_and_exit).never
@ssh.connect
Mario::Platform.forced = Mario::Platform::Linux
assert_nothing_raised { @ssh.connect }
end
end
@ -252,11 +256,15 @@ class SshTest < Test::Unit::TestCase
@stat.stubs(:owned?).returns(true)
File.stubs(:stat).returns(@stat)
Mario::Platform.stubs(:windows?).returns(false)
Mario::Platform.forced = Mario::Platform::Linux
end
teardown do
Mario::Platform.forced = Mario::Platform::Linux
end
should "do nothing if on windows" do
Mario::Platform.stubs(:windows?).returns(true)
Mario::Platform.forced = Mario::Platform::Windows7
File.expects(:stat).never
@ssh.check_key_permissions(@key_path)
end