3 class ContainerRequestTest < ActiveSupport::TestCase
4 def check_illegal_modify c
5 assert_raises(ActiveRecord::RecordInvalid) do
7 c.command = ["echo", "bar"]
11 assert_raises(ActiveRecord::RecordInvalid) do
13 c.container_image = "img2"
17 assert_raises(ActiveRecord::RecordInvalid) do
23 assert_raises(ActiveRecord::RecordInvalid) do
25 c.environment = {"FOO" => "BAR"}
29 assert_raises(ActiveRecord::RecordInvalid) do
31 c.mounts = {"FOO" => "BAR"}
35 assert_raises(ActiveRecord::RecordInvalid) do
37 c.output_path = "/tmp3"
41 assert_raises(ActiveRecord::RecordInvalid) do
43 c.runtime_constraints = {"FOO" => "BAR"}
47 assert_raises(ActiveRecord::RecordInvalid) do
53 assert_raises(ActiveRecord::RecordInvalid) do
61 def check_bogus_states c
62 assert_raises(ActiveRecord::RecordInvalid) do
68 assert_raises(ActiveRecord::RecordInvalid) do
75 test "Container request create" do
76 set_user_from_auth :active_trustedclient
77 cr = ContainerRequest.new
78 cr.command = ["echo", "foo"]
79 cr.container_image = "img"
82 cr.mounts = {"BAR" => "FOO"}
83 cr.output_path = "/tmpout"
84 cr.runtime_constraints = {}
86 cr.description = "bar"
89 assert_nil cr.container_uuid
90 assert_nil cr.priority
95 cr.command = ["echo", "foo3"]
96 cr.container_image = "img3"
98 cr.environment = {"BUP" => "BOP"}
99 cr.mounts = {"BAR" => "BAZ"}
100 cr.output_path = "/tmp4"
102 cr.runtime_constraints = {"X" => "Y"}
104 cr.description = "bar3"
107 assert_nil cr.container_uuid
110 test "Container request priority must be non-nil" do
111 set_user_from_auth :active_trustedclient
112 cr = ContainerRequest.new
113 cr.command = ["echo", "foo"]
114 cr.container_image = "img"
117 cr.mounts = {"BAR" => "FOO"}
118 cr.output_path = "/tmpout"
119 cr.runtime_constraints = {}
121 cr.description = "bar"
125 cr.state = "Committed"
126 assert_raises(ActiveRecord::RecordInvalid) do
131 test "Container request commit" do
132 set_user_from_auth :active_trustedclient
133 cr = ContainerRequest.new
134 cr.command = ["echo", "foo"]
135 cr.container_image = "img"
138 cr.mounts = {"BAR" => "FOO"}
139 cr.output_path = "/tmpout"
141 cr.runtime_constraints = {}
143 cr.description = "bar"
147 assert_nil cr.container_uuid
150 cr.state = "Committed"
155 c = Container.find_by_uuid cr.container_uuid
156 assert_equal ["echo", "foo"], c.command
157 assert_equal "img", c.container_image
158 assert_equal "/tmp", c.cwd
159 assert_equal({}, c.environment)
160 assert_equal({"BAR" => "FOO"}, c.mounts)
161 assert_equal "/tmpout", c.output_path
162 assert_equal({}, c.runtime_constraints)
163 assert_equal 1, c.priority
165 assert_raises(ActiveRecord::RecordInvalid) do
175 assert_equal 0, cr.priority
176 assert_equal 0, c.priority
181 test "Container request max priority" do
182 set_user_from_auth :active_trustedclient
183 cr = ContainerRequest.new
184 cr.state = "Committed"
185 cr.container_image = "img"
186 cr.command = ["foo", "bar"]
187 cr.output_path = "/tmp"
192 c = Container.find_by_uuid cr.container_uuid
193 assert_equal 5, c.priority
195 cr2 = ContainerRequest.new
196 cr2.container_image = "img"
197 cr2.command = ["foo", "bar"]
198 cr2.output_path = "/tmp"
203 act_as_system_user do
204 cr2.state = "Committed"
205 cr2.container_uuid = cr.container_uuid
210 assert_equal 10, c.priority
217 assert_equal 5, c.priority
224 assert_equal 0, c.priority
229 test "Independent container requests" do
230 set_user_from_auth :active_trustedclient
231 cr = ContainerRequest.new
232 cr.state = "Committed"
233 cr.container_image = "img"
234 cr.command = ["foo", "bar"]
235 cr.output_path = "/tmp"
240 cr2 = ContainerRequest.new
241 cr2.state = "Committed"
242 cr2.container_image = "img"
243 cr2.command = ["foo", "bar"]
244 cr2.output_path = "/tmp"
249 c = Container.find_by_uuid cr.container_uuid
250 assert_equal 5, c.priority
252 c2 = Container.find_by_uuid cr2.container_uuid
253 assert_equal 10, c2.priority
259 assert_equal 0, c.priority
262 assert_equal 10, c2.priority
266 test "Container cancelled finalizes request" do
267 set_user_from_auth :active_trustedclient
268 cr = ContainerRequest.new
269 cr.state = "Committed"
270 cr.container_image = "img"
271 cr.command = ["foo", "bar"]
272 cr.output_path = "/tmp"
278 assert_equal "Committed", cr.state
280 c = Container.find_by_uuid cr.container_uuid
281 assert_equal "Queued", c.state
283 act_as_system_user do
284 c.state = "Cancelled"
289 assert_equal "Final", cr.state
294 test "Container complete finalizes request" do
295 set_user_from_auth :active_trustedclient
296 cr = ContainerRequest.new
297 cr.state = "Committed"
298 cr.container_image = "img"
299 cr.command = ["foo", "bar"]
300 cr.output_path = "/tmp"
306 assert_equal "Committed", cr.state
308 c = Container.find_by_uuid cr.container_uuid
309 assert_equal "Queued", c.state
311 act_as_system_user do
317 assert_equal "Committed", cr.state
319 act_as_system_user do
325 assert_equal "Final", cr.state
329 test "Container makes container request, then is cancelled" do
330 set_user_from_auth :active_trustedclient
331 cr = ContainerRequest.new
332 cr.state = "Committed"
333 cr.container_image = "img"
334 cr.command = ["foo", "bar"]
335 cr.output_path = "/tmp"
340 c = Container.find_by_uuid cr.container_uuid
341 assert_equal 5, c.priority
343 cr2 = ContainerRequest.new
344 cr2.state = "Committed"
345 cr2.container_image = "img"
346 cr2.command = ["foo", "bar"]
347 cr2.output_path = "/tmp"
350 cr2.requesting_container_uuid = c.uuid
353 c2 = Container.find_by_uuid cr2.container_uuid
354 assert_equal 10, c2.priority
356 act_as_system_user do
357 c.state = "Cancelled"
362 assert_equal "Final", cr.state
365 assert_equal 0, cr2.priority
368 assert_equal 0, c2.priority