Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
romand committed Apr 17, 2012
1 parent da14c51 commit 325f9aa
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
1 change: 0 additions & 1 deletion test/data/dir1/dir2

This file was deleted.

Empty file added test/data/dir1/stub
Empty file.
1 change: 1 addition & 0 deletions test/data/dir2/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
20 changes: 14 additions & 6 deletions test/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def code_bundle(name,&block)

class << code
def worker_code(str)
Tempfile.open('worker') do |f|
f << str
f.close
merge_worker(f.path)
f.unlink
end
tmpdir = Dir.tmpdir + '/' + Digest::MD5.hexdigest(str)
Dir.mkdir tmpdir unless Dir.exist? tmpdir

tmpfname = tmpdir + '/worker.rb'
File.open(tmpfname, "w") { |f| f << str }

puts "created #{tmpfname}"
merge_worker(tmpfname)
end
end

Expand All @@ -22,6 +24,12 @@ def worker_code(str)
code
end

def inspect_zip(code)
zip_file = code.create_zip
yield Zip::ZipFile.open(zip_file)
File.unlink zip_file
end

class IWNGTest < Test::Unit::TestCase
attr_accessor :client

Expand Down
20 changes: 0 additions & 20 deletions test/test_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,4 @@ def _test_basic
log = client.tasks_log(task_id)
assert_equal( "hello\n", log, "worker stdout is in log" )
end

def test_symlinks
Dir.unlink './test/data/dir1/dir2' if
Dir.exist? './test/data/dir1/dir2'
Dir.chdir('test/data/dir1') do
File.symlink('./test/data/dir2', 'dir2')
end

code = code_bundle 'test_symlinks' do
merge_dir('data/dir1', 'data')
worker 'puts File.read("dir1/dir2/test")'
end

puts code.create_zip

File.unlink 'test/data/dir1/dir2'

assert true
end

end
32 changes: 30 additions & 2 deletions test/test_common_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_merge_file
merge_worker('test/hello.rb')
end

Zip::ZipFile.open(code.create_zip) do |zip|
inspect_zip(code) do |zip|
assert zip.find_entry('test/data/dir2/test')
end
end
Expand All @@ -28,9 +28,37 @@ def test_merge_dir
merge_worker('test/hello.rb')
end

Zip::ZipFile.open(code.create_zip) do |zip|
inspect_zip(code) do |zip|
assert zip.find_entry('test/data/dir2/test')
end
end

def test_symlinks
File.unlink 'test/data/dir1/dir2' if
File.symlink? 'test/data/dir1/dir2'

Dir.chdir('test/data/dir1') do
File.symlink('../dir2', 'dir2')
end

code = code_bundle 'test_symlinks' do
merge_dir('test/data/dir1', 'test/data')
merge_dir('test/data/dir2', 'test/data')
worker_code 'puts File.read("test/data/dir1/dir2/test")'
end

inspect_zip(code) do |zip|
assert_equal '../dir2', zip.read('test/data/dir1/dir2')
end

client.codes_create(code)
task_id = client.tasks_create('test_symlinks').id
client.tasks_wait_for(task_id)
log = client.tasks_log(task_id)

assert_equal "test", log

File.unlink 'test/data/dir1/dir2'
end

end

0 comments on commit 325f9aa

Please sign in to comment.