-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_builder.rb
113 lines (88 loc) · 3.3 KB
/
test_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
gem 'test-unit'
require 'test/unit'
require_relative 'helpers'
class BuilderTest < IWNGTest
def test_build_worker
main_file = "hello.go"
name = "HelloGo"
code = IronWorkerNG::Code::Ruby.new('build_worker.rb')
code.merge_gem 'iron_worker_ng'
code.merge_file "workers/#{main_file}"
code.merge_file 'workers/hello_go.worker'
#code.merge_exec(File.dirname(__FILE__) + '/hello.rb')
client.codes_create(code)
task_id = client.tasks.create('BuildWorker',
client.api.options.merge(
:name => name,
:build_command => "go build #{main_file}",
:exec => 'hello'
)).id
task = client.tasks_wait_for(task_id)
assert task
assert task.id == task_id
assert_equal "complete", task.status
log = client.tasks_log(task_id)
puts "LOG START"
puts log
puts "LOG END"
puts "Running #{name}..."
go_task_id = client.tasks.create(name).id
task = client.tasks_wait_for(go_task_id)
assert_equal "complete", task.status
log = client.tasks_log(go_task_id)
puts "LOG START"
puts log
puts "LOG END"
end
def test_ruby_build_from_github
# Usage would be via cli:
# iron_worker upload??? https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/hello_worker/hello.worker
worker_file_url = "https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/worker101/worker101.worker"
name = "RubyWorker101"
remote_build(name, worker_file_url)
# Now let's try queueing up a task for it
puts "Running #{name}..."
go_task_id = client.tasks.create(name, 'query' => 'bieber').id
task = client.tasks_wait_for(go_task_id)
assert_equal "complete", task.status
log = client.tasks_log(go_task_id)
puts "LOG START"
puts log
puts "LOG END"
end
def remote_build(name, worker_file_url)
code = IronWorkerNG::Code::Ruby.new('build_worker.rb')
code.merge_gem 'iron_worker_ng'
client.codes_create(code)
task_id = client.tasks.create('BuildWorker',
client.api.options.merge(
:name => name,
:worker_file_url => worker_file_url
)).id
task = client.tasks_wait_for(task_id)
assert task
assert task.id == task_id
log = client.tasks_log(task_id)
puts "LOG START"
puts log
puts "LOG END"
assert_equal "complete", task.status
end
# This one not only gets the code from github, but compiles it too.
def test_go_build_from_github
# Usage would be via cli:
# iron_worker upload??? https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/hello_worker/hello.worker
worker_file_url = "https://github.com/iron-io/iron_worker_examples/blob/master/go/hello_worker/hello.worker"
name = "HelloGoGithub"
remote_build(name, worker_file_url)
# Try queuing up a task for it
puts "Running #{name}..."
go_task_id = client.tasks.create(name).id
task = client.tasks_wait_for(go_task_id)
log = client.tasks_log(go_task_id)
puts "LOG START"
puts log
puts "LOG END"
assert_equal "complete", task.status
end
end