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) error_key(:no_env)
end end
class SSHUnavailableWindows < VagrantError
status_code(10)
error_key(:ssh_unavailable_windows)
end
class VirtualBoxInvalidOSE < VagrantError class VirtualBoxInvalidOSE < VagrantError
status_code(9) status_code(9)
error_key(:virtualbox_invalid_ose) error_key(:virtualbox_invalid_ose)

View File

@ -22,9 +22,8 @@ module Vagrant
# of options which override the configuration values. # of options which override the configuration values.
def connect(opts={}) def connect(opts={})
if Mario::Platform.windows? if Mario::Platform.windows?
error_and_exit(:ssh_unavailable_windows, raise Errors::SSHUnavailableWindows.new(:key_path => env.config.ssh.private_key_path,
:key_path => env.config.ssh.private_key_path, :ssh_port => port(opts))
:ssh_port => port(opts))
end end
options = {} 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_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. 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. 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: |- virtualbox_invalid_ose: |-
Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox. 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 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! Vagrant assumes that this means the command failed!
<%= command %> <%= 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: |- :system_invalid_class: |-
The specified system does not inherit from `Vagrant::Systems::Base`. The The specified system does not inherit from `Vagrant::Systems::Base`. The
specified system class must inherit from this class. 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) Vagrant::Util::Platform.stubs(:leopard?).returns(true)
end end
teardown do
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
end
should "fork, exec, and wait" do should "fork, exec, and wait" do
pid = mock("pid") pid = mock("pid")
@ssh.expects(:fork).once.returns(pid) @ssh.expects(:fork).once.returns(pid)
@ -78,18 +82,18 @@ class SshTest < Test::Unit::TestCase
end end
context "checking windows" do context "checking windows" do
teardown do
Mario::Platform.forced = Mario::Platform::Linux
end
should "error and exit if the platform is windows" do should "error and exit if the platform is windows" do
Mario::Platform.expects(:windows?).returns(true) Mario::Platform.forced = Mario::Platform::Windows7
@ssh.expects(:error_and_exit).with do |error_name, opts| assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect }
opts[:key_path] && opts[:ssh_port]
end
@ssh.connect
end end
should "not error and exit if the platform is anything other that windows" do should "not error and exit if the platform is anything other that windows" do
Mario::Platform.expects(:windows?).returns(false) Mario::Platform.forced = Mario::Platform::Linux
@ssh.expects(:error_and_exit).never assert_nothing_raised { @ssh.connect }
@ssh.connect
end end
end end
@ -252,11 +256,15 @@ class SshTest < Test::Unit::TestCase
@stat.stubs(:owned?).returns(true) @stat.stubs(:owned?).returns(true)
File.stubs(:stat).returns(@stat) 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 end
should "do nothing if on windows" do should "do nothing if on windows" do
Mario::Platform.stubs(:windows?).returns(true) Mario::Platform.forced = Mario::Platform::Windows7
File.expects(:stat).never File.expects(:stat).never
@ssh.check_key_permissions(@key_path) @ssh.check_key_permissions(@key_path)
end end