Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romand committed May 11, 2012
1 parent 6ae1445 commit cd6174a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
6 changes: 5 additions & 1 deletion bin/iron_worker
Expand Up @@ -23,6 +23,10 @@ command = 'tasks.create' if command == 'queue'
command = 'schedules.create' if command == 'schedule'
command = 'tasks.log' if command == 'log'

if level = ENV['LOG_LEVEL']
IronCore::Logger.logger.level = eval "::Logger::#{level}"
end

client = IronWorkerNG::Client.new

if command == 'codes.create'
Expand Down Expand Up @@ -193,7 +197,7 @@ elsif command == 'tasks.log'
opts = OptionParser.new do |opts|
opts.banner = "usage: iron_worker #{command} [OPTIONS]"

opts.on('-t --task-id ID', 'task id') do |v|
opts.on('-t', '--task-id ID', 'task id') do |v|
task_id = v
end

Expand Down
4 changes: 2 additions & 2 deletions lib/iron_worker_ng/client.rb
Expand Up @@ -57,10 +57,10 @@ def codes_get(code_id)

def codes_create(code)
zip_file = code.create_zip
@api.codes_create(code.name, zip_file, code.runtime, code.runner)
res = @api.codes_create(code.name, zip_file, code.runtime, code.runner)
File.unlink(zip_file)

true
OpenStruct.new(res)
end

def codes_delete(code_id)
Expand Down
2 changes: 1 addition & 1 deletion test/Rakefile
Expand Up @@ -40,7 +40,7 @@ Rake::TestTask.new do |t|
end

t.libs << "lib" << "test" << examples_tests_dir
files = FileList['test/**/**.rb',
files = FileList['test/**/test_**.rb',
examples_tests_dir + '/**/test_*.rb']
t.test_files = files.keep_if{ |f| f =~ Regexp.new(ENV['TESTP'] || '') }

Expand Down
2 changes: 2 additions & 0 deletions test/cli_runner.rb
@@ -0,0 +1,2 @@
$:.unshift('lib')
load 'bin/iron_worker'
6 changes: 4 additions & 2 deletions test/test_basic.rb
@@ -1,8 +1,8 @@
require 'helpers'

class BasicTest < IWNGTest
def _test_basic
code = IronWorkerNG::Code::Ruby.new('test_basic')
def test_basic
code = IronWorkerNG::Code::Ruby.new
code.merge_exec(File.dirname(__FILE__) + '/hello.rb')
client.codes_create(code)
task_id = client.tasks_create('test_basic').id
Expand All @@ -11,6 +11,8 @@ def _test_basic
assert task
assert task.id == task_id
assert_equal "complete", task.status
assert_equal 1, task.run_times
assert_equal "{}", task.payload

log = client.tasks_log(task_id)
assert_equal( "hello\n", log, "worker stdout is in log" )
Expand Down
47 changes: 47 additions & 0 deletions test/test_cli.rb
@@ -0,0 +1,47 @@
require 'helpers'

class CLITest < IWNGTest

def cli(*args)
if args.last.is_a? Hash
args.pop.each do |k,v|
args << "--" + k.to_s.gsub(/_/,'-') + " " + v.to_s
end
end

out = Tempfile.new('cli_output').path
args << "2>&1 >#{out}"

cmd = 'ruby test/cli_runner.rb ' + args.join(' ')
puts cmd

puts "----------------------------------------------------------"

ENV['LOG_LEVEL'] = 'DEBUG'
exec(cmd) if fork.nil?
Process.wait

puts File.read(out)

puts "----------------------------------------------------------"

assert $?.success?

File.read(out)
end

def test_basic
assert cli('codes.create', ruby_merge_exec: 'test/hello.rb') =~
/Upload successful/

assert cli('tasks.create', name: 'Hello') =~
/Queued up.*"id":"(.{24})"/

assert cli('tasks.log', '--live', task_id: $1) =~
/\nhello\n/

assert cli('schedules.create', name: 'Hello') =~
/Scheduled/
end

end
6 changes: 6 additions & 0 deletions test/test_code_create.rb
Expand Up @@ -29,4 +29,10 @@ def test_workerfile
end
end

def test_upload
resp = client.codes_create code_bundle('test/hello.rb')
assert_equal 200, resp.status_code, "status ok"
assert resp.id =~ /[0-9a-f]{24}/, "has id"
end

end

0 comments on commit cd6174a

Please sign in to comment.