Standardize on Util::Platform

This commit is contained in:
Mitchell Hashimoto 2011-07-09 16:51:04 -07:00
parent 1aed9f0f38
commit 5143556065
7 changed files with 10 additions and 27 deletions

View File

@ -1,6 +1,5 @@
require 'net/ssh' require 'net/ssh'
require 'net/scp' require 'net/scp'
require 'mario'
module Vagrant module Vagrant
# Manages SSH access to a specific environment. Allows an environment to # Manages SSH access to a specific environment. Allows an environment to
@ -27,7 +26,7 @@ module Vagrant
# process with an SSH process. This method optionally takes a hash # process with an SSH process. This method optionally takes a hash
# 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 Util::Platform.windows?
raise Errors::SSHUnavailableWindows, :key_path => env.config.ssh.private_key_path, raise Errors::SSHUnavailableWindows, :key_path => env.config.ssh.private_key_path,
:ssh_port => port(opts) :ssh_port => port(opts)
end end
@ -137,7 +136,7 @@ module Vagrant
# if needed, or on failure erroring. # if needed, or on failure erroring.
def check_key_permissions(key_path) def check_key_permissions(key_path)
# Windows systems don't have this issue # Windows systems don't have this issue
return if Mario::Platform.windows? return if Util::Platform.windows?
stat = File.stat(key_path) stat = File.stat(key_path)

View File

@ -1,5 +1,3 @@
require 'mario'
module Vagrant module Vagrant
# Vagrant UIs handle communication with the outside world (typically # Vagrant UIs handle communication with the outside world (typically
# through a shell). They must respond to the typically logger methods # through a shell). They must respond to the typically logger methods
@ -61,7 +59,7 @@ module Vagrant
def line_reset def line_reset
reset = "\r" reset = "\r"
reset += "\e[0K" unless Mario::Platform.windows? reset += "\e[0K" unless Util::Platform.windows?
reset reset
end end
end end

View File

@ -1,5 +1,4 @@
require 'rbconfig' require 'rbconfig'
require 'mario'
module Vagrant module Vagrant
module Util module Util
@ -53,7 +52,7 @@ module Vagrant
def tar_file_options def tar_file_options
# create, write only, fail if the file exists, binary if windows # create, write only, fail if the file exists, binary if windows
File::WRONLY|File::EXCL|File::CREAT|(Mario::Platform.windows? ? File::BINARY : 0) File::WRONLY | File::EXCL | File::CREAT | (windows? ? File::BINARY : 0)
end end
def platform def platform

View File

@ -2,7 +2,6 @@
$:.unshift(File.dirname(__FILE__)) $:.unshift(File.dirname(__FILE__))
require 'vagrant' require 'vagrant'
require 'mario'
require 'contest' require 'contest'
require 'mocha' require 'mocha'
@ -14,9 +13,6 @@ begin
rescue LoadError rescue LoadError
end end
# Silence Mario by sending log output to black hole
Mario::Platform.logger(nil)
# Add the I18n locale for tests # Add the I18n locale for tests
I18n.load_path << File.expand_path("../locales/en.yml", __FILE__) I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)

View File

@ -80,17 +80,13 @@ 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.forced = Mario::Platform::Windows7 Vagrant::Util::Platform.stubs(:windows?).returns(true)
assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect } assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @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.forced = Mario::Platform::Linux Vagrant::Util::Platform.stubs(:windows?).returns(false)
assert_nothing_raised { @ssh.connect } assert_nothing_raised { @ssh.connect }
end end
end end
@ -256,15 +252,11 @@ 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.forced = Mario::Platform::Linux Vagrant::Util::Platform.stubs(:windows?).returns(false)
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.forced = Mario::Platform::Windows7 Vagrant::Util::Platform.stubs(:windows?).returns(true)
File.expects(:stat).never File.expects(:stat).never
@ssh.check_key_permissions(@key_path) @ssh.check_key_permissions(@key_path)
end end

View File

@ -6,12 +6,12 @@ class PlatformTest < Test::Unit::TestCase
# This constant is not defined on non-windows platforms, so define it here # This constant is not defined on non-windows platforms, so define it here
File::BINARY = 4096 unless defined?(File::BINARY) File::BINARY = 4096 unless defined?(File::BINARY)
Mario::Platform.expects(:windows?).returns(true) Vagrant::Util::Platform.stubs(:windows?).returns(true)
assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
end end
should "not include binary bit on other platforms" do should "not include binary bit on other platforms" do
Mario::Platform.expects(:windows?).returns(false) Vagrant::Util::Platform.stubs(:windows?).returns(false)
assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY
end end
end end

View File

@ -17,7 +17,6 @@ Gem::Specification.new do |s|
s.add_dependency "archive-tar-minitar", "= 0.5.2" s.add_dependency "archive-tar-minitar", "= 0.5.2"
s.add_dependency "erubis", "~> 2.7.0" s.add_dependency "erubis", "~> 2.7.0"
s.add_dependency "json", "~> 1.5.1" s.add_dependency "json", "~> 1.5.1"
s.add_dependency "mario", "~> 0.0.6"
s.add_dependency "net-ssh", "~> 2.1.4" s.add_dependency "net-ssh", "~> 2.1.4"
s.add_dependency "net-scp", "~> 1.0.4" s.add_dependency "net-scp", "~> 1.0.4"
s.add_dependency "i18n", "~> 0.5.0" s.add_dependency "i18n", "~> 0.5.0"