Work around an issue where Dir.tmpdir under OS X behaves differently when in an SSH session and from the console
This commit is contained in:
parent
a131de53f1
commit
c9b0c3215e
|
@ -1,6 +1,6 @@
|
|||
require 'hydra/hash'
|
||||
require 'open3'
|
||||
require 'tmpdir'
|
||||
require 'hydra/tmpdir'
|
||||
require 'erb'
|
||||
require 'yaml'
|
||||
|
||||
|
@ -238,7 +238,7 @@ module Hydra #:nodoc:
|
|||
end
|
||||
|
||||
def heuristic_file
|
||||
@heuristic_file ||= File.join(Dir.tmpdir, 'hydra_heuristics.yml')
|
||||
@heuristic_file ||= File.join(Dir.consistent_tmpdir, 'hydra_heuristics.yml')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
require 'tmpdir'
|
||||
|
||||
class Dir
|
||||
def self.consistent_tmpdir
|
||||
if RUBY_PLATFORM =~ /darwin/i
|
||||
'/tmp' # OS X normally returns a crazy tmpdir, BUT when logged in via SSH, it is '/tmp'. This unifies it.
|
||||
else
|
||||
Dir.tmpdir
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
Given /^a target file$/ do
|
||||
@target_file = File.expand_path(File.join(Dir.tmpdir, 'hydra_test.txt'))
|
||||
@target_file = File.expand_path(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'))
|
||||
end
|
||||
|
||||
Given /^an alternate target file$/ do
|
||||
@target_file = File.expand_path(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'))
|
||||
@target_file = File.expand_path(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'))
|
||||
end
|
||||
|
||||
When /^I write "([^\"]*)" to the file$/ do |text|
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
|
||||
class WriteFileTest < Test::Unit::TestCase
|
||||
def test_write_a_file
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'tmpdir'
|
||||
require 'hydra/tmpdir'
|
||||
require 'spec'
|
||||
context "file writing" do
|
||||
it "writes to a file" do
|
||||
File.open(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'), 'a') do |f|
|
||||
File.open(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'), 'a') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'tmpdir'
|
||||
require 'hydra/tmpdir'
|
||||
require 'spec'
|
||||
context "file writing" do
|
||||
it "writes to a file" do
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'tmpdir'
|
|||
require 'spec'
|
||||
context "file writing" do
|
||||
it "writes to a file" do
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ class MasterTest < Test::Unit::TestCase
|
|||
Hydra::Master.new(:files => [test_file])
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA", File.read(target_file)
|
||||
report_file = File.join(Dir.tmpdir, 'hydra_heuristics.yml')
|
||||
report_file = File.join(Dir.consistent_tmpdir, 'hydra_heuristics.yml')
|
||||
assert File.exists?(report_file)
|
||||
assert report = YAML.load_file(report_file)
|
||||
assert_not_nil report[test_file]
|
||||
|
@ -88,7 +88,8 @@ class MasterTest < Test::Unit::TestCase
|
|||
:connect => 'localhost',
|
||||
:directory => File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')),
|
||||
:runners => 1
|
||||
}]
|
||||
}],
|
||||
:verbose => true
|
||||
)
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA", File.read(target_file)
|
||||
|
@ -104,8 +105,8 @@ class MasterTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "synchronize a test file over ssh with rsync" do
|
||||
local = File.join(Dir.tmpdir, 'hydra', 'local')
|
||||
remote = File.join(Dir.tmpdir, 'hydra', 'remote')
|
||||
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
|
||||
remote = File.join(Dir.consistent_tmpdir, 'hydra', 'remote')
|
||||
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
|
||||
[local, remote].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ class SyncTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "synchronize a test file over ssh with rsync" do
|
||||
local = File.join(Dir.tmpdir, 'hydra', 'local')
|
||||
remote = File.join(Dir.tmpdir, 'hydra', 'remote')
|
||||
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
|
||||
remote = File.join(Dir.consistent_tmpdir, 'hydra', 'remote')
|
||||
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
|
||||
[local, remote].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}
|
||||
|
||||
|
@ -58,9 +58,9 @@ class SyncTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "synchronize a test file over ssh with rsync to multiple workers" do
|
||||
local = File.join(Dir.tmpdir, 'hydra', 'local')
|
||||
remote_a = File.join(Dir.tmpdir, 'hydra', 'remote_a')
|
||||
remote_b = File.join(Dir.tmpdir, 'hydra', 'remote_b')
|
||||
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
|
||||
remote_a = File.join(Dir.consistent_tmpdir, 'hydra', 'remote_a')
|
||||
remote_b = File.join(Dir.consistent_tmpdir, 'hydra', 'remote_b')
|
||||
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
|
||||
[local, remote_a, remote_b].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ Test::Unit.run = false
|
|||
|
||||
class Test::Unit::TestCase
|
||||
def target_file
|
||||
File.expand_path(File.join(Dir.tmpdir, 'hydra_test.txt'))
|
||||
File.expand_path(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'))
|
||||
end
|
||||
|
||||
def alternate_target_file
|
||||
File.expand_path(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'))
|
||||
File.expand_path(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'))
|
||||
end
|
||||
|
||||
def test_file
|
||||
|
|
Loading…
Reference in New Issue