Permalink
Browse files

another test

  • Loading branch information...
1 parent da14c51 commit 325f9aa014b07b4e974f3cdddacd7fe987ced699 @romand romand committed Apr 17, 2012
Showing with 45 additions and 29 deletions.
  1. +0 −1 test/data/dir1/dir2
  2. 0 test/data/dir1/stub
  3. +1 −0 test/data/dir2/test
  4. +14 −6 test/helpers.rb
  5. +0 −20 test/test_basic.rb
  6. +30 −2 test/test_common_features.rb
View
View
No changes.
View
@@ -0,0 +1 @@
+test
View
@@ -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
@@ -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
View
@@ -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
@@ -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
@@ -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.