Permalink
Browse files

Merge pull request #34 from romand-ironio/master

more tests
  • Loading branch information...
2 parents d915e32 + 618bfca commit 017cf95c9e3e214b04d2ace00cda7795cd53cb78 romand-ironio committed Apr 23, 2012
@@ -30,7 +30,7 @@
# once worker merged, following attempts will be ignored
code.merge_exec('anything')
-#> code.worker.path.end_with? '/worker.rb'
+#> code.features.find{|f| f.is_a? IronWorkerNG::Feature::Ruby::MergeExec::Feature }.path.end_with? '/worker.rb'
# if worker requires some gems, we
@@ -51,6 +51,8 @@ def initialize(*args, &block)
exec = args[0][:exec] || args[0]['exec'] || args[0][:worker] || args[0]['worker']
merge_exec(exec) unless exec.nil?
+ else
+ raise "Wrong arguments" unless args.empty?
end
unless block.nil?
View
@@ -3,8 +3,8 @@
require './lib/iron_worker_ng.rb'
-def code_bundle(name,&block)
- code = IronWorkerNG::Code::Ruby.new(name)
+def code_bundle(*args,&block)
+ code = IronWorkerNG::Code::Ruby.new(*args)
class << code
def worker_code(str)
@@ -15,11 +15,11 @@ def worker_code(str)
File.open(tmpfname, "w") { |f| f << str }
puts "created #{tmpfname}"
- merge_worker(tmpfname)
+ merge_exec(tmpfname)
end
end
- code.instance_eval(&block)
+ code.instance_eval(&block) if block_given?
code
end
@@ -44,3 +44,13 @@ def setup
:project_id => project_id )
end
end
+
+module IronWorkerNG
+ module Code
+ class Base
+ def exec_path
+ exec = @features.find{|f| f.is_a? IronWorkerNG::Feature::Ruby::MergeExec::Feature } and exec.path
+ end
+ end
+ end
+end
View
@@ -3,7 +3,7 @@
class BasicTest < IWNGTest
def _test_basic
code = IronWorkerNG::Code::Ruby.new('test_basic')
- code.merge_worker(File.dirname(__FILE__) + '/hello.rb')
+ code.merge_exec(File.dirname(__FILE__) + '/hello.rb')
client.codes_create(code)
task_id = client.tasks_create('test_basic').id
client.tasks_wait_for(task_id)
View
@@ -0,0 +1,47 @@
+require 'helpers'
+
+class CodeCreateTest < IWNGTest
+
+ def test_wrong_args
+ assert_raises RuntimeError do
+ code_bundle('Hello', 'hello.rb')
+ end
+
+ assert_raises RuntimeError do
+ code_bundle('hello.rb', :name => 'Hello')
+ end
+
+ assert_raises RuntimeError do
+ client.codes_create(code_bundle(:worker_path => 'hello.rb',
+ :name => 'Hello'))
+ end
+ end
+
+ def test_create
+ code = code_bundle('test/hello.rb')
+ assert_equal File.expand_path('test/hello.rb'), code.exec_path
+ assert_equal 'Hello', code.name
+
+ code = code_bundle('asdfasdf')
+ assert_equal nil, code.exec_path
+ assert_equal 'asdfasdf', code.name
+
+ code = code_bundle(:exec => 'test/hello.rb', :name => 'dfdfd')
+ assert_equal File.expand_path('test/hello.rb'), code.exec_path
+ assert_equal 'dfdfd', code.name
+
+ code = code_bundle
+ assert_equal nil, code.exec_path
+ assert_equal nil, code.name
+ end
+
+ def test_workerfile
+ Dir.chdir( Dir.mktmpdir ) do
+ File.open('hello.rb', 'w') { |f| f << "puts 'hello'" }
+ File.open('Workerfile', 'w') { |f| f << "exec 'hello.rb'" }
+
+ assert code_bundle.exec_path.end_with? 'hello.rb'
+ end
+ end
+
+end
@@ -6,7 +6,7 @@ class CommonFeaturesTest < IWNGTest
def test_merge_file
code = code_bundle('test') do
merge_file('test', 'test/data/dir2')
- merge_worker('test/hello.rb')
+ merge_exec('test/hello.rb')
end
inspect_zip(code) do |zip|
@@ -17,7 +17,7 @@ def test_merge_file
def test_merge_file_no_dest
code = code_bundle('test') do
merge_file('Gemfile')
- merge_worker('test/hello.rb')
+ merge_exec('test/hello.rb')
end
inspect_zip(code) do |zip|
@@ -36,7 +36,7 @@ def test_merge_dir_check
def test_merge_dir
code = code_bundle('test') do
merge_dir('test/data/dir2', 'test/data')
- merge_worker('test/hello.rb')
+ merge_exec('test/hello.rb')
end
inspect_zip(code) do |zip|
@@ -47,7 +47,7 @@ def test_merge_dir
def test_merge_dir_no_dest
code = code_bundle('test') do
merge_dir('test')
- merge_worker('test/hello.rb')
+ merge_exec('test/hello.rb')
end
inspect_zip(code) do |zip|
@@ -78,7 +78,7 @@ def test_symlinks
client.tasks_wait_for(task_id)
log = client.tasks_log(task_id)
- assert_equal "test", log
+ assert_equal "test\n", log
File.unlink 'test/data/dir1/dir2'
end

0 comments on commit 017cf95

Please sign in to comment.